Jump to content

multi-select in a form


george

Recommended Posts

When I have a form with a multi select

<select multiple="multiple" id="forClass"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select

how do I read the selected values? I have a little button that calls a function called letsC

<script type="text/javascript">function letsC() {	x = document.getElementById('tForm')	param = x.elements[0].id  + "=" + x.elements[0].value + '\n';	document.getElementById('show_me').innerHTML = param;}</script>

But this will only show the initial value selected, and not the subsequent ones. OK, I think I found my answer:

	y = document.getElementById('forClass');	for (i=0;i<y.length;i++) {		param = param + y.options[i].text + y.options[i].[b]selected[/b] + '\n';				}	document.getElementById('show_me').innerHTML = param;

though I did not see "selected" as an property of options[] in the http://www.w3schools.com/htmldom/coll_select_options.asp I guessed at it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...