Click to See Complete Forum and Search --> : Password Verification
tomyknoker
05-27-2003, 04:33 AM
hi everyone,
I am new to javascript and am having trouble creating this:
I have a text field called "password" and another called "vpw". "vpw" field is meant to be a password field and when the user submits the form if the "vpw" field doesn't match what they ahve typed into the first field "password" I want an alert to po up...
thanks agfain,
tom
AdamGundry
05-27-2003, 05:08 AM
Something like this?
<form onsubmit="return Verify()">
<input type="password" id="password">
<input type="password" id="vpw">
<input type="submit">
</form>
<script type="text/javascript">
function Verify(){
if (document.getElementById('password').value != document.getElementById('vpw').value){
alert("The passwords do not match.");
return false;
}
}
</script>
Adam
tomyknoker
05-27-2003, 07:56 AM
hi,
thanks for the help, just wondering if there is a simpler way (maybe longer I know) to do this because it is actually for an assignment but we have never used getelementByid before...or is this the only way,
tom
Yes, there is no need to use getElementById... Try it like this:
<form name="myform" onsubmit="return Verify()">
<input type="password" name="password">
<input type="password" name="vpw">
<input type="submit">
</form>
<script type="text/javascript">
function Verify(){
if (document.myform.password.value != document.myform.vpw.value){
alert("The passwords do not match.");
return false;
}
}
</script>
Note: This is actually the prefered way to reference forms...
AdamGundry
05-27-2003, 09:36 AM
Sorry, I've been stuck in getElementById mode for days now. :) Thanks, Pyro.
Adam