In JavaScript, you can get the selected value of a <select>
element using the value
property of the select element. Here's a simple example:
<select id="mySelect">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
And the JavaScript:
var selectElement = document.getElementById('mySelect');
var selectedValue = selectElement.value;
console.log(selectedValue); // This will log the value of the currently selected option
This will give you the value of the currently selected option. If you want to get the selected option's text instead of its value, you can use the text
property of the selected option:
var selectElement = document.getElementById('mySelect');
var selectedOption = selectElement.options[selectElement.selectedIndex];
var selectedText = selectedOption.text;
console.log(selectedText); // This will log the text of the currently selected option