Get selected value in dropdown list using JavaScript

The drop-down list selectedIndex property in HTML DOM is sets or returns the index of the selected option in a drop-down list.
  1. Get from selectedIndex property.
selectObject.selectedIndex
  1. Set the Select selectedIndex property.
selectObject.selectedIndex = number
The index starts at 0 and if no element is selected then it return -1. If the drop-down list allows multiple selections it will only return the index of the first option selected.
run this source code Browser View


Full Source | JavaScript
<!DOCTYPE html> <html> <body> <div> <select id="items"> <option value="1">One</option> <option value="2">Two</option> <option value="3" selected="selected">Three</option> <option value="4">Four</option> <option value="5">Five</option> </select> <br><br> <button onClick="GetSelectedItem('items');">Get Selected Item</button> </div> <script> function GetSelectedItem(sItem) { var i = document.getElementById(sItem); var strSel = "Value is: " + i.options[i.selectedIndex].value + " and Text is: " + i.options[i.selectedIndex].text; alert(strSel); } </script> </body> </html>


Javascript drop down selected item

jQuery

$("#elementId :selected").text(); // The text content of the selected option $("#elementId :selected").val(); // The value of the selected option