...

View Full Version : verifying password fields then submit form...



disneyfan
03-08-2005, 01:40 PM
Here's ya one to help me with...

When the user clicks the submit button a function should compare the values entered in the password boxes. If the values are the same, the forms data should be submitted. If different alert the user. The forms data should NOT be sent before verifying.

can you help?


<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Learning Javascript</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function chkPassword() {
if (document.infoForm.txtPass1.value == document.infoForm.txtPass2.value) {
// FORM SUBMIT CODE???

else
//ALERT USER VALUES DOES NOT MATCH

}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>

</head>
<body>
<form action="mailto:myemailaddress@home.com"
Method="post" enctype="text/plain" name="infoForm">
<p>Email: <input type="text" name="txtEmail" size="24"> Password:
<input type="password" name="txtPass1" size="20"> Verify Password:
<input type="password" name="txtPass2" size="20"></p>
<p>
<input type="submit" value="Submit" name="button_Submit" onclick=chkPassword()>
<input type="reset" value="Reset" name="button_Reset">
</p>
</form>
</body>
</html>

tboss132
03-08-2005, 03:29 PM
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Learning Javascript</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function chkPassword() {
if (document.infoForm.txtPass1.value == document.infoForm.txtPass2.value) {
// FORM SUBMIT CODE???
return true
else
//ALERT USER VALUES DOES NOT MATCH
alert("Values do not match")
return false
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>

</head>
<body>
<form action="mailto:myemailaddress@home.com"
Method="post" enctype="text/plain" name="infoForm">
<p>Email: <input type="text" name="txtEmail" size="24"> Password:
<input type="password" name="txtPass1" size="20"> Verify Password:
<input type="password" name="txtPass2" size="20"></p>
<p>
<input type="submit" value="Submit" name="button_Submit" onclick=chkPassword()>
<input type="reset" value="Reset" name="button_Reset">
</p>
</form>
</body>
</html>


When a form action calls a javascript function, it checks the return value
"return true" submits the form, "return false" cancels submission.

BTW - Next time you want to post some code, make sure it's wrapped within Code Tags.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum