How to get the selected value from DropDown (select) using value property in JavaScript?
I have a DropDown with some options and a button.
When i select one option and click on the button i want to fetch the value.
How can i do it in JavaScript?
Hi makenzi.exc,
First reference the DropDown using document.querySelector and get the value using the HTML DOM value property.
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" name="Fruit"> <option value=""></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 Value. var selectedValue = ddlFruits.value; alert("Selected Value: " + selectedValue); }; </script> <input type="button" value="Submit" onclick="GetSelectedFruit()" /> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.