Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> <script src="https://code.jquery.com/jquery-3.5.0.min.js"></script> </head> <body> <select id="my-select"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <option value="option3">Option 3</option> </select> <script> var selectBox = document.getElementById("my-select"); var selectedValue = selectBox.value; alert(selectedValue); // prints the value of the selected option to the console </script> </body> </html>