Created
April 29, 2020 11:52
-
-
Save guillaumecabanel/0b70b847056a87207ef5295c162b40da to your computer and use it in GitHub Desktop.
JS | How to get selected option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const select = document.querySelector('select'); | |
const valueFromSelectedOption = select.options[select.selectedIndex].value; | |
console.log(valueFromSelectedOption); // => "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select> | |
<option value="1">test1</option> | |
<option value="2" selected="selected">test2</option> | |
<option value="3">test3</option> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment