how to read multiple user selections under <Select>

liunx

Guest
I have a form select tag as below. <br />
<br />
<select name="myselect" size="4" MULTIPLE> <br />
<option value="1">First</option> <br />
<option value="2" >Second</option> <br />
<option value="3">Third</option> <br />
<option value="4">Fourth</option> <br />
<option value="5">Fifth</option> <br />
</select><br />
<br />
If User selects say options 1 and 3, how can I evaluate them? <br />
<br />
When I am trying to print using document.all("myselect").value, it is printing the first one selected from the list!!! How can I get all the values selected?<!--content-->store them as variables or log them into a data base. What exactly are you trying to do, if you tell me your goal I can maybe help you think of a better way to go about doing what you want to do.<!--content-->I am trying to evaluate the selections made by user with a client side scripting (javascript/vbscript) and see if the selections are ok or not, based on some business rules. I want to do it, without leaving the page... <br />
<br />
If I am ready to go to a new page, then I can use a request("myselect") and get all the values selected in one string, exactly the way I am trying to get with client side scripting<!--content-->well I suggest doing it server side but if you insist on doing it client side just store them all in a string<br />
x+ = something.value;<br />
or x = x + something.value;<br />
just run what on select of an option and parse it all into one string.<!--content--><script type="text/javascript"><br />
//<![CDATA[<br />
function getOptions()<br />
{<br />
var o = document.forms[0][0].options, s = '';<br />
for(i=0; i<o.length; i++) if(o.selected) s += o.value + '\n';<br />
alert(s ? s : 'No options currently selected.');<br />
}<br />
//]]><br />
</script><form action="#"><br />
<div><br />
<select size="5" multiple="multiple"><br />
<option value="option 1">option 1</option><br />
<option value="option 2">option 2</option><br />
<option value="option 3">option 3</option><br />
<option value="option 4">option 4</option><br />
<option value="option 5">option 5</option><br />
</select><br />
<input type="button" value="Get selected options" onclick="getOptions();" /><br />
</div><br />
</form><!--content-->
 
Back
Top