- Instant help with your JavaScript coding problems

Get selected option from select using JavaScript

Question:
How to get selected option from select using JavaScript?
Answer:
const selectedValue = document.getElementById("color-id").value;
Description:

To get the selected value from a dropdown list, i.e. the selected option from a select element, using vanilla JavaScript simply get the element and read the value attribute.

 

The code above reads the selected value from the following HTML select:

<select id="color-id">
    <option value="1">Red</option>
    <option value="2" selected="selected">Green</option>
    <option value="3">Blue</option>
</select>
Share "How to get selected option from select using JavaScript?"