george Posted August 6, 2007 Share Posted August 6, 2007 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 More sharing options...
jesh Posted August 6, 2007 Share Posted August 6, 2007 "selected" is a property of the Option object and "options" is an array of those Option objects.You can read more about it here:http://www.w3schools.com/htmldom/dom_obj_option.asphttp://www.w3schools.com/htmldom/prop_option_selected.asp Link to comment Share on other sites More sharing options...
george Posted August 7, 2007 Author Share Posted August 7, 2007 Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.