By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Check if both passwords match

P: 2
Hello,

I think I nearly have this figured out,

however, what i'd like to do is to check and see if both passwords entered are the same. If they are not what i'd like to do is ask the user to re-enter the new one and confirm the second password again. My current code alerts the user that their passwords do not match and does not ask them to enter the new one and confirm the other password again. Any ideas as to how to loop it until both passwords match?
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <title>New Page 1</title>
  6.  
  7. <script type="text/javascript">
  8.  
  9. function test() {
  10.  
  11. var pwd = prompt("Enter a new pwd","")
  12.  
  13. var pwd2 = prompt("Re-enter new pwd","")
  14.  
  15.   if(pwd != pwd2) {
  16.     alert('Your passwords do not match. Please type again.');
  17.     return false;
  18.   }
  19.   return true;
  20. }
  21.  
  22. </script>
  23.  
  24.  
  25. </head>
  26.  
  27. <body onload="test()">
  28.  
  29. </body>
  30.  
  31. </html>
Jun 12 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
call test() in the if() part of the condition.
Jun 12 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.