This tutorial will show you how to get the selected text, value and index from dropdownlist using JavaScript.
<!DOCTYPE html> <html> <body> <select id="Select1" name="D1" onChange='getDropdownElements();'> <option value="sel">-- Select any item --</option> <option value="se">Software Engineer</option> <option value="ce">Civil Engineer</option> <option value="me">Mechanical Engineer</option> <option value="ee">Electrical Engineer</option> </select> </body> </html>
<script lang="javascript" type="text/javascript"> function getDropdownElements() { var dropDownBox = document.getElementById("Select1"); var selIndex = dropDownBox.selectedIndex; var selValue = dropDownBox.options[selIndex].value; var selText = dropDownBox.options[selIndex].text; alert("Selected Text : " + selText); alert("Selected Value : " + selValue); alert("Selected Item Index : " + selIndex); } </script>