Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Ensuring Two Form Fields Have Identical Information

By Will Bontrager
2005-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


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function