retrieving multiple selected options in drop down menu

liunx

Guest
hi all,<br />
<br />
I have a drop down menu (using select) where users are able to select multiple options. how do i retrieve the individual options after they had done a multiple selection?<br />
<br />
pls help.<br />
Thx!!<!--content-->do you want to use client side javascript, or some server side code?<!--content--><html><br />
<head><br />
<title>untitled</title><br />
<script type="text/javascript" language="JavaScript"><br />
<br />
function getOpts(sel) {<br />
if (sel) {<br />
var selectedOpts = new Array();<br />
for (var opts=0; opts<sel.length; ++opts) {<br />
if (sel[opts].selected) {<br />
selectedOpts[selectedOpts.length] = sel[opts].value;<br />
}<br />
}<br />
} alert(selectedOpts); // demo //<br />
return selectedOpts;<br />
}<br />
<br />
</script><br />
</head><br />
<body onload="document.forms[0].reset()"><br />
<br />
<form><br />
<select name="choices" size="5" multiple><br />
<option value="choice1">choice 1</option><br />
<option value="choice2">choice 2</option><br />
<option value="choice3">choice 3</option><br />
<option value="choice4">choice 4</option><br />
<option value="choice5">choice 5</option><br />
</select><br><br><br />
<input type="button" value="Show Selected Options" onclick="getOpts(this.form.choices)"><br />
</form><br />
</body><br />
</html><!--content-->
 
Back
Top