I’m wanting to do a form validation before it is submitted, and I am having a problem inside my JS checkform() function getting a hold of the “product[]” values, which in the form are in array notation.
For some reason, I am getting JS errors such as “product has no properties” etc. when I try to use “product” or “product[]” in various ways.
I’m not too experienced in JS. Things like getElementById(‘product[]’).selectedIndex are not working. I did a big search on the web, but found nothing that worked.
What I want to do ultimately is get the validation function to return false (i.e. a bad form submission) if what in the drop-down select box the user has selected is the first option.
Can anyone assist? Thanks in advance.
function checkform
{
if ( ??? )
{
alert(“Please select an option”);
return true;
}
else
{
return false;
}
}
<FORM ACTION=”
<INPUT TYPE=”hidden” NAME=”userid” VALUE=”6887906″>
<INPUT TYPE=”hidden” NAME=”product[]” VALUE=”BLACKTSHIRT”>
<INPUT TYPE=”hidden” NAME=”price” VALUE=”22.00″>
<br>
<br>
<font size=”2″>Size/font>
<select name=”product[]” id=”product[]”>
<option selected>Select</option>
<option>M</option>
<option>L</option>
<option>XL</option>
</select>
<p>
<input name=”imageField22″ type=”image” src=”images/add_to_cart.gif” width=”70″ height=”30″ border=”0″>
</p>
</FORM>