'How do you get the currently selected <option> in a <select> via JavaScript?

How do you get the currently selected <option> of a <select> element via JavaScript?



Solution 1:[1]

The .selectedIndex of the select object has an index; you can use that to index into the .options array.

Solution 2:[2]

var payeeCountry = document.getElementById( "payeeCountry" );
alert( payeeCountry.options[ payeeCountry.selectedIndex ].value );

Solution 3:[3]

Using the selectedOptions property:

var yourSelect = document.getElementById("your-select-id");
alert(yourSelect.selectedOptions[0].value);

It works in all browsers except Internet Explorer.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy E
Solution 2 Andreas
Solution 3 Finesse