How to get selected option value on DropDownList (Select) change in JavaScript.
<select id="ddlFruits"> <option value="">Select</option> <option value="1">Apple</option> <option value="2">Mango</option> <option value="3">Orange</option> </select>
Hi makenzi.exc,
Refer below example.
HTML
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> Select Fruit: <select id="ddlFruits" onchange="GetSelectedFruit()"> <option value="">Select</option> <option value="1">Apple</option> <option value="2">Mango</option> <option value="3">Orange</option> </select> <script type="text/javascript"> function GetSelectedFruit() { // Referencing DropDownList. var ddlFruits = document.querySelector('#ddlFruits'); // Referencing Selected Index. var selectedIndex = ddlFruits.selectedIndex; if (selectedIndex > 0) { // Referencing Selected Option. var selectedOption = ddlFruits.options[selectedIndex]; // Referencing Selected Value. var selectedValue = selectedOption.value; alert("Selected Value: " + selectedValue); } }; </script> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.