Ensuring Two Form Fields Have Identical Information
By Will Bontrager2005-03-11
The JavaScript
This JavaScript code can be put into the HEAD or the BODY area of the web page. If in the BODY area, it should be somewhere above the form.
<script type="text/javascript" language="JavaScript">
<!--
function BothFieldsIdenticalCaseSensitive() {
var one = document.FormName.FieldA.value;
var another = document.FormName.FieldB.value;
if(one == another) { return true; }
alert("Oops, both fields must be identical.");
return false;
}
function BothFieldsIdenticalCaseInsensitive() {
var one = document.FormName.FieldA.value.toLowerCase();
var another = document.FormName.FieldB.value.toLowerCase();
if(one == another) { return true; }
alert("Oops, both fields must be identical.");
return false;
}
//-->
</script>
As you've noticed, the two JavaScript function names are BothFieldsIdenticalCaseSensitive() and BothFieldsIdenticalCaseInsensitive()
As the function names imply, one checks for identical information, case sensitive. The other checks for identical information, case insensitive.
To check with case insensitivity, the form field values are both converted to all lower case before the comparison is made. That's the only difference in the code of the two functions.
Specify the function name of your choice for the onclick value in the form's submit button field.
Tutorial Pages:
» Ensuring Two Form Fields Have Identical Information
» The Form
» The JavaScript
» Integration Considerations
» Form Fields with Un-Identical Information
Copyright 2004 Bontrager Connection, LLC
