0

I'm taking a look at some existing code on our contact form, and it seems one of our JS guys has put two functions with the same name, one after the other. Can anybody advise how/if both these functions might execute?

     function check_webtolead_fields(){
        if (check_form('WebToLeadForm')) {
            alert("form sent");
            //document.WebToLeadForm.submit();
            return true;
        }
        return false;
    }

        function check_webtolead_fields(){
        if(document.getElementById('bool_id') != null){
            var reqs=document.getElementById('bool_id').value;
            bools = reqs.substring(0,reqs.lastIndexOf(';'));
            var bool_fields = new Array();
            var bool_fields = bools.split(';');
            nbr_fields = bool_fields.length;
            for(var i=0;i<nbr_fields;i++){
                if(document.getElementById(bool_fields[i]).value == 'on'){
                    document.getElementById(bool_fields[i]).value = 1;
                }
                else{
                document.getElementById(bool_fields[i]).value = 0;
                }
            }
        }
  ....
Barney
  • 1,820
  • 5
  • 29
  • 50
  • 2
    This is an error - not a syntax error, but a coding error. The second function will replace the first, after which there's no way to call the first one. – nnnnnn Mar 05 '14 at 11:24

1 Answers1

3

Only the second function will be called - the first one will be overridden.

athms
  • 948
  • 5
  • 8