A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/API/HTMLSelectElement/value below:

HTMLSelectElement: value property - Web APIs

HTMLSelectElement: value property

Baseline Widely available

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

A string containing the value of the first selected <option> element in this <select> element, or the empty string if no options are selected.

Examples Retrieving the selected value
<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>
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = text;
}

const select = document.querySelector("#bird-select");
select.addEventListener("change", () => {
  log(`Selection: ${select.value}`);
});
#log {
  height: 20px;
  padding: 0.5rem;
  border: 1px solid black;
}
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4