Entry
How do I check whether a FORM property is a SELECT or in array of input elements?
May 16th, 2000 15:38
Martin Honnen,
If you have multiple form elements with the same name in one FORM you
get that reflected in client side js as an array
document.formName.fieldName
with a length property. Thus one way to check whether you have a single
radio button or a radio group is
if (document.formName.fieldName.length)
If you have however also SELECT elements in your form that check is not
sufficient as these have a length property too. Therefore you need to
check the type property too in that case:
if (document.formName.fieldName.length
&& typeof document.formName.fieldName.type == 'undefined')
// you have an array