Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password verification javascript

Status
Not open for further replies.

bdasp1

Technical User
Jan 9, 2002
11
0
0
US
quick one for ya: my boss asked me to write a script that will verify that your confirmation password is the same as the password that you entered. simple enough. however, he wants the onBlur event to check those 2 fields and returnFocus to the first field if the entries do not match. for example, you have the following form:

name:
e-mail address:
username:

password:
re-enter password:

cc#:
exp. date:

so the customer fills in their name, e-mail, username, password and re-enters password. now upon click to the next field(or tabbing to the next field), the 2 passwords are compared. if they match, nothing happens. if they do not match, the customer receives an alert and the cursor is automatically returned to the password field. again, my boss doen't want much does he. i'm still working on this, but so far, no luck. any help at all would be greatly appreciated. thanks to all!
 
hi bdasp1,
this is what you need:

<html>
<head>
<script>
function check_fields() {

if (document.form1.input1.value != document.form1.input2.value) {
alert(&quot;Values do not match!&quot;);
document.form1.input2.focus();
}
}
</script>
</head>
<body>
<form name=&quot;form1&quot; >
<input type=&quot;password&quot; name=&quot;input1&quot;>
<input type=&quot;password&quot; name=&quot;input2&quot; onBlur=&quot;check_fields()&quot;>
</body>
</html>

However, I don't recommend to use onBlur event here, because it happens always when focus leaves text field, no matter what user does: clicks some button or switches to anothr window.

good luck
 
Thank you so much. You guys are great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top