[Javascript] Form validation

Cutter (JavaScript List) java.script at seacrets.com
Tue Jan 20 08:13:19 CST 2004


I am writing a form validation script whereby:

1)   I create an array of field names
2)   I pass this array and the form (this.form) to the valCheck function
3)   I loop through each item in the array and evaluate the field to 
determine if it is a select or not
4)   I check to see if a value has been entered/selected
5)   If no value then I alert the user they must enter a value before 
they continue

What I want to do next is where it goes awry. I want to focus() on the 
field that still needs information. I have tried this in a number of ways.

form.array[i].focus();
form.sName.focus(); // sName is a string equivelant of the array item

I have even tried passing the form name instead of the form object.

formName.array[i].focus();
form[formName].array[i].focus();
formName.sName.focus();
form[formName].sName.focus();

What am I doing wrong here?

Cutter




More information about the Javascript mailing list