So I'm having a cross-browser JavaScript issue.
I've got a <select>
DOM element that has some descendent <option>
element with selected=true
.
In Firefox, I can just do select_elt.value
to get the value of the selected option, but this seems not to work in IE6 (which I need to support).
I tried to iterate through the select_elt.getElementsByTagName('option')
to find the selected <option>
, which I could do, but option_elt.value
still doesn't give me the value of that option.
So what is the appropriate way to get the value of an option or select element in IE6 (yes, I know I should switch to jQuery or some other cross-platform library, and I may yet, but now I'm curious about how this is done at all in IE6)?
This is the most cross-browser compatible way (in my experience) to do that:
var mySelect = document.getElementById('mySelect');
alert(mySelect.options[mySelect.selectedIndex].value);