SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot boognish's Avatar
    Join Date
    Sep 2005
    Location
    Leeds
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confirm email validation not working... please help!

    I'm having trouble getting the following scipt to work. It's a basic validation which validates the email, the confirms the email again. However it's not working. Can anyone see what I'm doing wrong?

    Thanks!

    Code:
    <script type="text/javascript">
    function validate_email(field,alerttxt)
    {
    with (field)
      {
      apos=value.indexOf("@");
      dotpos=value.lastIndexOf(".");
      if (apos<1||dotpos-apos<2)
        {alert(alerttxt);return false;}
      else {return true;}
      }
    }
    
    
    function checkEmail() {
    var checkem = document.getElementById("em").value
    with (field) {
      if (value != checkem) {
      alert(alerttxt);return false;
        }
      else
        {
        return true;
    }
    }
    }
    
    
    function validate_form(thisform)
    {
    with (thisform)
      {
    if (validate_email(em,"Email must be valid!")==false)
      {em.focus();return false;}
    else if (checkEmail(em2,"Confirm email must match")==false)
      {em2.focus();return false;}
      }
    }
    </script>
    
    
    <form action="send.php" onSubmit="return validate_form(this)" method="post">
    <div class="label">Email:*</div>
    <input type="text" id="em" name="em" class="width_190" />
    			  
    <div class="label">Confirm email:*</div>
    <input type="text" id="em2" name="em2" class="width_190" /> 
    <input type="submit" />
    </form>

  2. #2
    SitePoint Zealot boognish's Avatar
    Join Date
    Sep 2005
    Location
    Leeds
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Figured it out if anyone ever needs it for reference...
    Code:
    function checkEmail() {
    var checkem = document.getElementById("em").value;
    var checkem2 = document.getElementById("em2").value;
      if (checkem != checkem2) {
      alert("Confirm email must match");return false;
        }
      else
        {
        return true;
    }
    }
    
    function validate_form(thisform)
    {
    with (thisform)
      {
    
    if (validate_email(em,"Email must be valid!")==false)
      {em.focus();return false;}
    else if (checkEmail()==false)
      {em2.focus();return false;}
      }
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •