Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Help with Select Box Validation


Message #1 by anne.do@c... on Thu, 19 Dec 2002 14:33:51
Anne,

"document.formname.Interviewers.value" will only return the first selected
option value. You'll need to loop through the selected options and count how
many are selected. Something along the lines of:

function testing(){
var x = 0
for (i=0; i<document.form1.Interviewers.options.length; i++){
	if (document.form1.Interviewers.options[i].selected) x++
}
alert(x)
}


-----Original Message-----
From: anne.do@c... [mailto:anne.do@c...]
Sent: Thursday, December 19, 2002 9:34 AM
To: javascript
Subject: [javascript] Help with Select Box Validation


I have a select box with many option values in my form called Interviewers:

Please select at least three interviwers:
<select name="Interviewers" multiple size=4>
<option value="1">Mary Alston
<option value="2">John Doe
etc....... 
</select>

I want at least 3 options choosen from the select box before the form will 
submit.  Since the document.formname.Interviewers.value will equal "1,2,3" 
as a string how can I validate it to check that at least 3 interviwers 
were selected?

  Return to Index