get value of selected index javascript code example
Example 1: javascript to get value of dropdown
var e = document.getElementById("elementId");
var value = e.options[e.selectedIndex].value;
var text = e.options[e.selectedIndex].text;
Example 2: javascript get selected option
let selectElement = document.getElementById("selectElement");
let valueSelected = selectElement.options[selectElement.selectedIndex].value; // get selected option value
var text= selectElement.options[selectElement.selectedIndex].text; //get the selected option text
Example 3: get index of selected option javascript
$("#sel").attr("selectedIndex")
// or
$("#sel")[0].selectedIndex
//or
$(this).prop('selectedIndex')