My functions not working!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Naha
    New Member
    • Feb 2007
    • 41

    #1

    My functions not working!!!

    Hi, Can some one help me? I dont know why my checkEmail function is not working, it gives errors.

    Code:
    <html>
    <head><title>Registration Details</title>
    <SCRIPT LANGUAGE="JavaScript">
    
    
    
    /**
    
    
    function processForm1() {
    var form1 = document.formOne;
     if (form1.firstname.value==""){
     alert("you must fill in your first name")
     formOne.firstname.focus();
     }
     else if (form1.lastname.value==""){
     alert("you must fill in your lastname")
     formOne.lastname.focus();
     }
     else if (form1.postcode.value==""){
     alert("you must fill in your postcode")
     formOne.postcode.focus();
     }
     else if (form1.dateofbirth.value==""){
     alert("you must fill in your DOB")
     formOne.dateofbirth.focus();
     }
     else if (form1.contactphonenumber.value==""){
     alert("you must fill in your phone number")
     formOne.contactphonenumber.focus();
     }
    
      else if (form1.emailaddress.value==""){
     alert("you must fill in your email address")
     formOne.emailaddress.focus();
     }
    
    
     
     else { 
    	controlForm = parent.frame2.document.controlForm
    	controlForm.firstname.value=form1.firstname.value
    	controlForm.lastname.value=form1.lastname.value
    	controlForm.address.value=form1.address.value
    	controlForm.city.value=form1.city.value
    	controlForm.county.value=form1.county.value
    	controlForm.postcode.value=form1.postcode.value
    	controlForm.country.value=form1.country.value
    	controlForm.contactphonenumber.value=form1.contactphonenumber.value
    	controlForm.dateofbirth.value=form1.dateofbirth.value
    	controlForm.emailaddress.value=form1.emailaddress.value
    	controlForm.mypassword.value=form1.mypassword.value
    	location.href="login.html"
    	
    }
    
    }**/
    
    function checkEmail() {
    var emailFilter=/^/w+([/.-]?/w+)*@;
      if(emailFilter.test(document.form1.emailaddress))
    return true
    else{
    alert(“invalid email address”)
     formOne.emailaddress.focus();
    }
     
     }
    
     
    
     
    </script>
    </head>
    
    <body>
    <form method="GET" action="http://localhost:8081/controlform.html" NAME="formOne"    >
    
    <center>
    <h1>Registration Details</h1>
    <br><br>
    First Name <input type="text" name="firstname" value=""><br><br>
    Last Name <input type="text" name="lastname" value=""><br><br>
    Address <input type="text" name="address" value=""><br><br>
    City <input type="text" name="city" value=""><br><br>
    County (optional) <input type="text" name="county" value=""><br><br>
    Post Code <input type="text" name="postcode" value=""><br><br>
    Country <input type="text" name="country" value=""><br><br>
    Contact Phone Number <input type="text" name="contactphonenumber" value=""><br><br>
    Date of Birth <input type="text" name="dateofbirth" value=""><br><br>
    Email Address <input type="text" name="emailaddress" value=""><br><br>
    Password (minimum 6 characters) <INPUT TYPE=PASSWORD NAME="mypassword"><br><br>
    <input type="BUTTON" NAME="Submit"  value="--SUBMIT--" onClick="checkEmail()">
    </center>
    </form>
    </body>
    </html>
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    if(emailFilter. test(document.f orm1.emailaddre ss))

    needs to be

    if(emailFilter. test(document.f ormOne.emailadd ress))


    .test isn't anything so figure out what your problem is there


    and your regular expression isn't declared as a regular expression.

    and its not correct.

    Comment

    • Naha
      New Member
      • Feb 2007
      • 41

      #3
      ok, i have created the function checkemail2, and its also giving me errors.

      Code:
      <html>
      <head><title>Registration Details</title>
      <SCRIPT LANGUAGE="JavaScript">
      
      
      
      /**
      
      
      function processForm1() {
      var form1 = document.formOne;
       if (form1.firstname.value==""){
       alert("you must fill in your first name")
       formOne.firstname.focus();
       }
       else if (form1.lastname.value==""){
       alert("you must fill in your lastname")
       formOne.lastname.focus();
       }
       else if (form1.postcode.value==""){
       alert("you must fill in your postcode")
       formOne.postcode.focus();
       }
       else if (form1.dateofbirth.value==""){
       alert("you must fill in your DOB")
       formOne.dateofbirth.focus();
       }
       else if (form1.contactphonenumber.value==""){
       alert("you must fill in your phone number")
       formOne.contactphonenumber.focus();
       }
      
        else if (form1.emailaddress.value==""){
       alert("you must fill in your email address")
       formOne.emailaddress.focus();
       }
      
      
       
       else { 
      	controlForm = parent.frame2.document.controlForm
      	controlForm.firstname.value=form1.firstname.value
      	controlForm.lastname.value=form1.lastname.value
      	controlForm.address.value=form1.address.value
      	controlForm.city.value=form1.city.value
      	controlForm.county.value=form1.county.value
      	controlForm.postcode.value=form1.postcode.value
      	controlForm.country.value=form1.country.value
      	controlForm.contactphonenumber.value=form1.contactphonenumber.value
      	controlForm.dateofbirth.value=form1.dateofbirth.value
      	controlForm.emailaddress.value=form1.emailaddress.value
      	controlForm.mypassword.value=form1.mypassword.value
      	location.href="login.html"
      	
      }
      
      }
      
      function checkEmail() {
      var form1 = document.formOne;
      var emailFilter=/^/+w([/.-]?/+w)*@$/;
        if(emailFilter.test(document.form1.emailaddress))
      return true
      else{
      alert(“invalid email address”)
       formOne.emailaddress.focus();
      }
       
       }**/
      
       
       function checkEmail2() {
       var error = "";
       var form1 = document.formOne;
       var emailFilter=/^.+@.+\..{2,3,4,6}$/;
       var email= form1.emailaddress.value;
      if (!(emailFilter.test(email)))  {
             error = "Invalid email!\n";
          }
      return error;   
       }
       
       
      </script>
      </head>
      
      <body>
      <form method="GET" action="http://localhost:8081/controlform.html" NAME="formOne"    >
      
      <center>
      <h1>Registration Details</h1>
      <br><br>
      First Name <input type="text" name="firstname" value=""><br><br>
      Last Name <input type="text" name="lastname" value=""><br><br>
      Address <input type="text" name="address" value=""><br><br>
      City <input type="text" name="city" value=""><br><br>
      County (optional) <input type="text" name="county" value=""><br><br>
      Post Code <input type="text" name="postcode" value=""><br><br>
      Country <input type="text" name="country" value=""><br><br>
      Contact Phone Number <input type="text" name="contactphonenumber" value=""><br><br>
      Date of Birth <input type="text" name="dateofbirth" value=""><br><br>
      Email Address <input type="text" name="emailaddress" value=""><br><br>
      Password (minimum 6 characters) <INPUT TYPE=PASSWORD NAME="mypassword"><br><br>
      <input type="BUTTON" NAME="Submit"  value="--SUBMIT--" onClick="checkEmail2()">
      </center>
      </form>
      </body>
      </html>

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        See this page for info. on regular expressions. Your slashes are wrong and you haven't defined it properly.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Aah, we both posted at the same time - didn't realise.

          Again, I reiterate, your email regular expression is incorrect.

          Try using something like:
          Code:
          /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/
          (adapted from the link I gave you).

          Also, you have commented out all your functions!!

          Comment

          Working...