[thelist] Javascript form validation

Roee Rubin webdesign1 at irubin.com
Wed Oct 31 00:30:59 CST 2001


I have been using a very simple script to perform client side javascript
validation. I am looking for something more generic.

Basically - I have two types of fields, text and select boxes. I am
interested in specifying the field name that I will like to validate at the
top of the function and the code will determine the type of field it is and
perform the validation (which for now could be just validating if data
exists or not).

Below is a snippet of the code I currently use, which is nothing to brag
about. Any help is appreciated.


function validateform() {

ectedIndex].value == "") {
		alert("Invalid field");
		return false;

	if (document.mainform.Qty.value == "") {
		alert("Invalid field");
		return false;

	if (document.mainform.Length.value == "") {
		alert("Invalid field");
		return false;

	if (document.mainform.Width.value == "") {
		alert("Invalid field");
		return false;

	// ... and so forth

	return true;

Roee Rubin
Irubin Consulting
roee at irubin.com

More information about the thelist mailing list