Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

confirm password on keyup (Before form Submit)

Hello All;
I need to check the password and confirmpassword before the user clicks submit.
I have found all sorts of articles, but all of them are on FormSubmit.
I need to check:
Either while the user is typing into the confirm (This is the preferred method)
(or)
Once the user finishing typing into the confirmpassword.

Thank You
Carrzkiss
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

1) Create a basic page with your server side code that will show the id of the row based on the password based on form input.  If using asp request.form not request or request.querystring.
<%
theID=0
message="No Dice, not here"
' "rs=select * from myContacts where password="&request.form("pass")
if not rs.bof or not rs.eof then
    theID=rs("id")
    message="I found it:"&theID
end if
response.write message
%>

Open in new window



2) Jquery ajax

<input type="text" id="pass" name="pass">
<div id="message"></div>

<script>
//you will want to do this as a function

var pass=$('#pass').val()

$.ajax({
  type: "POST",
  url: "myASPpage.asp",
  data: { pass: pass }
}).done(function( msg ) {
  $('#message').text(msg);
});

</script>

Open in new window

Avatar of Wayne Barron

ASKER

Hey padas, hope you are doing well.

Unfortunately, I cannot use this.
This is used for a new registration, so there is not database entry for the potential member yet.

I am testing
<input type="password" name="password" />
<input type="password" name="confirmpassword" />

Not against a database entry.
$("#confirmpasswordID").bind("keyup blur, function() {
        if( $("#passwordID").val() == $("#confirmpasswordID").val() ) {
             $("#spanOrAnyOtherContainerError").hide();
        }
        else {
             $("#spanOrAnyOtherContainerError").show();
        }
})

Open in new window


<input type="password" name="password" id="passwordID" /><span id="spanOrAnyOtherContainerError">bad password</span><br />
<input type="password" name="confirmpassword" id="confirmpasswordID" />

Open in new window

http://jsbin.com/utajow/1/edit
 
$('#confirm').focusout(function() {
   var pass=$('#password').val();
   var conf=$('#confirm').val();
   if (pass!=conf){
      $('#messg').html('Password does not match');
   }
});

Open in new window

  <input type="password" id="password" name="password" />
<input type="password" id="confirm" name="confirmpassword" />
  <div id="messg"></div>

Open in new window

Hello Leak.
I am unable to get your code to work.
Also, the
<span id="spanOrAnyOtherContainerError">bad password</span>
Is this not supposed to be invisible until it is called?
@padas.
I tested the link, and if I type in identical entries, it states that it is
Password does not match
code corrected here : http://jsfiddle.net/LgWKq/2/

@padas, sorry did not saw your posts before...
@leak
Everyone is welcome to join in on the fun.
I like your code, however, I am trying to make it show ONLY if the passwords are different.
So, I changed the

             $("#spanOrAnyOtherContainerError").show();
        }
        else {
             $("#spanOrAnyOtherContainerError").hide();
and

<span id="spanOrAnyOtherContainerError" style="display:none;">

This works, but it shows really fast, than it disappears again.
I would like have it only show, if it is different.
work fine for me here : http://jsfiddle.net/LgWKq/3/
Once you start typing in the first field, the "bad password" shows.
It needs to only show if it is bad, not when the other field is empty.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Leak, I gave you the points, as your code got me where I needed to be at.
I also added in my last code as assisted.

Have a good one.
Carrzkiss
thank you
your welcome leak, and thank you.
Have an awesome rest of the week.

Carrzkiss