Click to See Complete Forum and Search --> : Referencing an element with array like name


Shane43
11-28-2002, 01:51 PM
Hey guys-

I want to use javascript to error check a form before it is submitted. The problem I am having is that the input names are in the form of an array name (and I cannot change the names because the action script needs them to be this way).

Normally if I had an <input name="email"> I could use:
if(form.email.value=="") alert("blah...");

But, if the input name resembles an array, like <input name="user[email]"> then how do I access that value?

Using:
if(form.user[email].value=="") ...
does not work.

Any suggestions?

Thanks,
Shane

AdamGundry
11-28-2002, 03:04 PM
How about using the form's elements array?

I.e. you would use form.elements[0].value instead of form.user[email].value. Thus you would be able to iterate over all the input elements using a for loop.

If you only want to access a few elements, there are probably better ways.

Hope this helps

Adam