Avatar of Wayne Barron
Wayne Barron
Flag 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
jQueryJavaScriptAJAX

Avatar of undefined
Last Comment
Wayne Barron

8/22/2022 - Mon
Scott Fell

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

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.
leakim971

$("#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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Scott Fell

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

Wayne Barron

ASKER
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?
Wayne Barron

ASKER
@padas.
I tested the link, and if I type in identical entries, it states that it is
Password does not match
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
leakim971

code corrected here : http://jsfiddle.net/LgWKq/2/

@padas, sorry did not saw your posts before...
Wayne Barron

ASKER
@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.
leakim971

work fine for me here : http://jsfiddle.net/LgWKq/3/
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Wayne Barron

ASKER
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
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Wayne Barron

ASKER
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
leakim971

thank you
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Wayne Barron

ASKER
your welcome leak, and thank you.
Have an awesome rest of the week.

Carrzkiss