Check selected item in <select>-Roll?
So, I got a <select>
-Roll with multiple items. How can I check via DOM which item was selected? I think I'd usually know it but I'm having a big blackout 开发者_JAVA百科the whole day today...
Javascript:
//Almost any modern browser
document.getElementById("select-element").value;
//for some old browsers
var select = document.getElementById("select-element");
select.options[select.selectedIndex].value;
html:
<select id="select-element">
<option value="1">1</option>
<option value="2">2</option>
<select>
精彩评论