Skip to content

Instantly share code, notes, and snippets.

@Postnov
Created June 1, 2018 14:32
Show Gist options
  • Save Postnov/71614031e5126203599889ffe32afcf6 to your computer and use it in GitHub Desktop.
Save Postnov/71614031e5126203599889ffe32afcf6 to your computer and use it in GitHub Desktop.
Get selected option on native javaScript
<select id="LOCATION" required>
<option value="">Выберите регион</option>
<option value="MSK">Москва</option>
<option value="SPB">Санкт-Петербург</option>
<option value="KRD">Краснодар</option>
</select>
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