Forum Moderators: coopster & phranque

Message Too Old, No Replies

Javascript to compare two form fields

Want to verify that two email addresses are same

         

hutchins13

5:31 pm on Feb 14, 2002 (gmt 0)

10+ Year Member



I'm trying to write a form which uses a javascript to compare two email address fields. This is to hopefully reduce the number of email address errors (ie. typos) when people checkout. Below is what I am using. The problem is that the script always says that the two fields are different no matter what I enter. Can anyone see what I am doing wrong?

<script language="JavaScript">
<!--
function checkEmail() {
if (document.TheForm.Email != document.TheForm.EmailVerify) {
alert ('The email addresses do not match. Please re-enter.')
return false;
}
}
//-->
</script>

<form action="customer.cfm" method="POST" name="TheForm">
<table>
<tr>
<td>Email:</td>
<td><input type="Text" name="Email" value="" size="30" maxlength="150"></td>
</tr>
<tr>
<td>Verify Email:</td>
<td><input type="Text" name="EmailVerify" value="" size="30" maxlength="150"></td>
</tr>
<tr>
<td colspan="2"><input type="Submit" name="PlaceOrder" value="Continue" onClick="return checkEmail();"></td>
</tr>
</table>
</form>

txbakers

5:48 pm on Feb 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to check the values of the object against each other. Right now your code is just checking the object itself.

document.TheForm.Email.value

Also, I don't think you want to put an onClick event on a submit button. Better to set it to a "button" type and call the submit in the JS function.

hutchins13

6:15 pm on Feb 14, 2002 (gmt 0)

10+ Year Member



That fixed it. Thanks for your help!