...

View Full Version : validate multiselect menu item



ventura
09-24-2003, 06:20 PM
how can i validate that at least one item is checked in a select menu?



<form>
<select name="to" id="to" size="6" multiple>
<option value="1">Hospital 1</option>
<option value="2">Hospital 2</option>
<option value="3">Hospital 3</option>
</select>
</form>

cheesebag
09-24-2003, 06:27 PM
if (document.forms[0].to.selectedIndex == -1)
{.....bad dog!


}

beetle
09-24-2003, 06:32 PM
I think the default selectedIndex is -1 only when the size attribute is greater than 1. Otherwise, it's 0.

Just FYI.

cheesebag
09-24-2003, 06:39 PM
validate multiselect menu item

<select name="to" id="to" size="6" multiple> :D

beetle
09-24-2003, 08:21 PM
Indeed :)

But, what I said is true, for single selects. Multiples are always -1 by default.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum