PDA

View Full Version : Checking if passwords match on registration.



eGeekee
12 Jul 2010, 12:48 AM
So, for a simple little example of what I want to do...

------------------------------------------------

REGISTRATION FORM
<br>
Desired Username: <input type="text" name="username">
<br>
Password: <input type="text" name="password">
<br>
Verify pass: <input type="text" name="passwordcheck">

------------------------------------------------

I want to rig up something that will automatically check the values posted in "password" and "passwordcheck" before the form is submitted making sure that they match each other and give a little error message if they don't. Ideally, if they don't match it would also prevent the form from even being submitted. My knowledge of Javascript is pretty basic, in fact it primarily consists of what's covered under the "basic" category in w3schools.com's Javascript tutorial, as well as a very modest understanding of form validation in the "advanced" section of the same site. So I haven't had much luck trying to accomplish this myself.

Can anyone offer any help? I don't need anything especially fancy (since if it were it would likely be beyond my comprehension at the moment) I just need it to be functional.

<CrGeary.com/>
12 Jul 2010, 06:37 AM
On the form tag, add the following:


onsubmit="check_passwords( this );"

in the head section have:



function check_password( vtarget ){

if( vtarget.password.value != vtarget.passwordcheck.value )
return false;
else
return true;

}

I think thats it.