How to determine which option is selected from a select box

Does anyone know how to retrieve an option selected from a dropdown select list?

I am using the value document.getElementById ("mySelect"). He does not work...

0


a source to share


3 answers


document.getElementById("mySelect").options[document.getElementById("mySelect").selectedIndex].value

      



+5


a source


Are you sure there is a value in the dropdown? Have you specified values ​​for it?

<select id="dropdownBox">
<option value="val1">value 1</option>
<option value="val2">value 2</option>
<option value="val3">value 3</option>
<option value="val4">value 4</option>
</select>

      



Values: val1, val2 ...

0


a source


It is better to do something like:

var o = document.getElementById("mySelect");
o.options[o.selectedIndex].value;

      

JQuery Option:

$("#mySelect").val();

      

0


a source







All Articles