Entry
how can I get in a script all values sended by a select with the multiple option?
May 7th, 2000 23:59
Rey Nuņez, Dani C, Olivier WATTE,
You can use a for loop to check every option in the select, an get the
value from those that are selected. Use:
select.options[index].selected (boolean that is true if selected)
select.options[index].value
This example shows how the selected property can be used to retrieve
multiple selected options in a SELECT object (IE4+, NN5+).
<form name="theForm">
<table cellpadding=5>
<tr>
<td><select id="theSelect" multiple size=5>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
<option>Item 4</option>
<option>Item 5</option></select></td>
<td><input type="button" onclick="getSels()" value="Get
Selected"></td></tr>
</table></form>
<script language="JavaScript">
<!--
function getSels(){
var list=document.forms['theForm'].elements['theSelect'];
var sels="";
for (i=0;i<list.options.length;i++)
if (list.options[i].selected)
sels += list.options[i].text+"\n";
if (sels.length>0) alert("You have selected: \n"+sels);
else alert("You have not selected anything.");
}
//-->
</script>