2 Replies Latest reply on Apr 23, 2011 10:52 AM by HealthcareHelper

    How do I revise "if" syntax in form validation JavaScript?

    HealthcareHelper Level 1

      I added a script to my "Contact" page to validate any submitted email. Just one problem: the visitor is not required to give me their reply email if they don't want to. I want the script to validate if they input an email, but do nothing if they leave that form field blank. This should be easy, but as a result of having gotten into the habit of avoiding Web desgn that relies on JavaScript, I don't have the know-how to fix a script when I decide it's needed!  Link:

       

      http://www.keithpurtell.com/kthings/mail02.htm

        • 1. Re: How do I revise "if" syntax in form validation JavaScript?
          Ned Murphy Adobe Community Professional & MVP

          Just leave the conditional in but have it do nothing...

           

              if (fld.value == "") {
                   // do nothing
              } else if (!emailFilter.test(tfld)) {         //test for illegal characters
                  fld.style.background = 'Yellow';
                  error = "Please enter a valid email address.\n";
              } else if (fld.value.match(illegalChars)) {
                  fld.style.background = 'Yellow';
                  error = "The email address contains illegal characters.\n";
              } else {
                  fld.style.background = 'White';
              }

          • 2. Re: How do I revise "if" syntax in form validation JavaScript?
            HealthcareHelper Level 1

            My first response was "Doh! It's easy!" (And thank you Ned, by the way.) Then I tested it. The form sends the contents through an old-fashioned cdosys ("classic" ASP) file, which kicks back the error "CDO.Message.1 error '8004020d'   At least one of the From or Sender fields is required, and neither was found."   I don't know if anyone in the Dreamweaver forum does classic ASP, but I'll give this a shot as a new thread, and go find an ASP forum if no reply here.

             

            Heck, I can edit the cdosys, maybe I just need to puzzle out the logic tree and do the ASP equivalent of the JavaScript edit you suggested?