Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    201
    Thanks
    51
    Thanked 0 Times in 0 Posts

    Trying to create a simple password verification

    Hi All,

    I am trying to create a script that will compare two text fields on my form and submit the form if the fields match or give an alert if they don't. It's for a password verification. For some reason the fields are not returning any value. I tried setting alerts for each text field variable and got back the following:

    [Object HTMLInputElement]

    I tried adding innerHTML when setting the variables but that returns nothing (an empty string or null). It seems like this should work... It's sooo simple but I don't know why it's not. If anyone can pinpoint what I am doing wrong I would be grateful:

    Code:
    <script type="text/javascript">
    function verifyPass() {
    var pass=document.getElementById("password");
    var vpass=document.getElementById("verifyPassword");
      if (pass==vpass) {
    //    alert(pass);
    //    alert(vpass);
    //    alert("the form should be submitted");
        document.getElementById("frmAddUser").submit();
      }else{
    //    alert(pass);
    //    alert(vpass); 
        alert("The passwords do not match.");
      }
    }
    </script>

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    You forgot to add the word value. That's all.

    ("verifyPassword").value

  • Users who have thanked DrDOS for this post:

    MaDmiX (07-16-2012)

  • #3
    Regular Coder MaDmiX's Avatar
    Join Date
    Feb 2012
    Location
    Charlotte, NC
    Posts
    201
    Thanks
    51
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DrDOS View Post
    You forgot to add the word value. That's all.

    ("verifyPassword").value
    Doh!!! I am embarassed :-)
    Working now. Many thanks.

    Ken

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,313
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Code:
    alert("The passwords do not match.");
    return false;
    }
    If you omit return false the form will submit regardless. And you must call your function with return verifyPass()

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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