
Originally Posted by
bbrant
I've been asked to create a new form that will require users to enter their e-mail address and the re-enter it for validation purposes. [...] I know I can do form validation and compare the e-mail address using CF but would rather use JavaScript [...]
There's certainly no reason not to use client-side code in addition to server-side validation, but it's never a substitute.
Code:
function validate(form) {
var controls = form.elements;
/* Validation.
* ...
*/
if (controls['e-mail'].value != controls['mail-confirmation'].value) {
alert('Your e-mail address and its confirmation do not match.');
return false;
}
/* More validation.
* ...
*/
return true;
}
HTML Code:
<form action="..." method="..." onsubmit="return validation(this);">
<table>
<!-- ... -->
<tr>
<th><label for="e-mail">E-mail address</label>:</th>
<td>
<input id="e-mail" type="text" name="e-mail" value="">
</td>
</tr>
<tr>
<th><label for="mail-confirmation">Confirm address</label>:</th>
<td>
<input id="mail-confirmation" type="text" name="mail-confirmation" value="">
</td>
</tr>
<!-- ... -->
</table>
</form>

Originally Posted by
djr33
dunno how to get the value of a form field.
The comp.lang.javascript newsgroup FAQ (and the linked notes) will be of use.
Mike
Bookmarks