9951 explained code solutions for 126 technologies


javascriptGet selected option text of a dropdown (select) box


var sel = document.querySelector('select');
var selected = sel.options[sel.selectedIndex].text;ctrl + c
var sel = document.querySelector('select')

selects needed select element

var selected

will contain selected option text

sel.selectedIndex

returns selected option index

sel.options

array with select options