Given the HTML:
<select id="mySelect">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>
and the javascript:
var e = document.getElementById('mySelect');
To get the value of the select I can use e.value
and e.options[e.selectedIndex].value
.
I am aware that e.options[e.selectedIndex].value
will give me the selected value (1,2 or 3) and e.options[e.selectedIndex].text
would give me test1, test2, test3 depending on which is selected.
Is it ok to use just e.value
? was this a problem in old browsers?
which is more correct: e.value
vs e.options[e.selectedIndex].value
?