Select element onchange
-
10-07-2019 - |
Question
How can i acces an select element if it has been selected?
var select = document.getElementById("select");
if(select.selected == true)
doesnt work any idea?
Solution
document.getElementById("mySelect").value
or
var selObj = document.getElementById("mySelect"); selObj.options[selObj.selectedIndex].value;
OTHER TIPS
The DOM tree is something like
Select
|-option
|-option
`-option
it is not the select node which can be selected. As such, you need to get the select, browse the childs, and test if the child is selected until you find one.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow