Click to See Complete Forum and Search --> : Question about validating a multiple select box...


kj2w
09-16-2003, 02:44 PM
I have a multiple select box. Before I submit my form, I'd like to make sure that something is selected otherwise throw an alert box.

Example:

<form name="myForm" action="test.html" method="post">
<select name="sB" multiple>
<option name="test">Test</option>
<option name="test2">Test2</option>
<option name="test3">Test3</option>
</select>
</form>

<script laguage="JavaScript">
if(?document.myForm.sb.checked?){
document.myForm.submit();
}
</script>

Any Ideas,
Jason

Khalid Ali
09-16-2003, 03:14 PM
replace this

if(?document.myForm.sb.checked?){
document.myForm.submit();
}

with the one below

var lb = document.myForm.sb;
if(sb.selectedIndex>-1){
document.myForm.submit();
}