Created
June 1, 2018 14:32
-
-
Save Postnov/71614031e5126203599889ffe32afcf6 to your computer and use it in GitHub Desktop.
Get selected option on native javaScript
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 id="LOCATION" required> | |
<option value="">Выберите регион</option> | |
<option value="MSK">Москва</option> | |
<option value="SPB">Санкт-Петербург</option> | |
<option value="KRD">Краснодар</option> | |
</select> |
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
var select = document.getElementById('LOCATION'); | |
select.addEventListener('change', function() { | |
var n = select.options.selectedIndex, | |
textSelect = document.getElementById("LOCATION").options[n].text; | |
console.log(textSelect) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment