toxicandy 2 Junior Poster

So I have the following code:

 <script>
     function validateForm() {
              var homePhone = document.forms["volForm"]["hphone"].value;
              var mobPhone = document.forms["volForm"]["mphone"].value;
              var workPhone = document.forms["volForm"]["wphone"].value;
              var ehomePhone = document.forms["volForm"]["ehphone"].value;
              var emobPhone = document.forms["volForm"]["ehphone"].value;
              var fname = document.forms["volForm"]["fname"].value;
              var lname = document.forms["volForm"]["lname"].value;
              var digiSig = document.forms["volForm"]["digiSig"].value;
              var digiSplit = digiSig.split(" ");
              if((homePhone.length == 0 && mobPhone.length == 0) && workPhone.length == 0){
                alert("Please fill out either a home phone, mobile phone or work phone so that we can contact you.");
                return false;
              }else if(ehomePhone.length == 0 && emobPhone.length == 0){
                alert("Please fill out a home phone or mobile phone for your emergency contact.");
                return false;
              }else if(digiSig.length != 0){
                if(digiSplit[0] != fname && digiSplit[1] != lname)
                  alert("Please make sure your digital signature matches your first and last name and is in the format of fist name (space) last name");
                return false;
              }
            }
    </script>

The problem is that the digiSig validation doesn't run. When I submit my form it runs this function and currently I have the firstName set as test and the last name set as test and then the digisigature is test test1 but the alert is never appearing and the form won't submit because of that reason. I have inserted alerts around that final else if but none of them run either. The other two else blocks work and the phone validation is working fine. Anyone know why this isn't running properly? The point of this script is to make sure that the first name entered and last name entered at the top of the form in the fields fname and lname are the same name entered in the digitial signature at the bottom which should be fname lname (seperated by a space). If the name doesn't mtach it is supposed to throw the alert box and not submit the form. the onsubmit in the <form> looks like this: onsubmit="return validateForm()"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.