Since there is no direct way to get the selected value in the listbox you have to get it by iterating over the list.For same the code is given below.
Below code will print all values in the listbox which were selected but you can modifiy the code as per your requirement.
HTML code :
<select id="listboxName">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
Javascript code :
var mySelect = document.getElementById("listboxName");
for (var i = 0; i < mySelect.options.length; i++) {
if (mySelect.options[i].selected)
document.write(" mySelect.options[i].text\n")
}
Hope this helps :)
Thank you that really helped
ReplyDelete