HTMLSelectElement: value property
The HTMLSelectElement.value property contains the value of the first selected <option> element associated with this <select> element.
This property can also be set directly, for example to set a default value based on some condition.
Value
Examples
Retrieving the selected value
html
<label for="bird-select">Choose a bird:</label>
<select name="birds" id="bird-select">
<option value="">--Please choose an option--</option>
<option value="Scarlet ibis">Scarlet ibis</option>
<option value="Marabou stork">Marabou stork</option>
<option value="Roseate spoonbill">Roseate spoonbill</option>
</select>
<pre id="log"></pre>
js
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = text;
}
const select = document.querySelector("#bird-select");
select.addEventListener("change", () => {
log(`Selection: ${select.value}`);
});
Specifications
| Specification |
|---|
| HTML Standard # dom-select-value-dev |
Browser compatibility
BCD tables only load in the browser
See also
- The
<select>HTML element, implementing this interface.