Back to Content

HTMLSelectElement: validity property

files/en-us/web/api/htmlselectelement/validity/index.md

latest928 B
Original Source

{{APIRef("HTML DOM")}}

The validity read-only property of the {{domxref("HTMLSelectElement")}} interface returns a {{domxref("ValidityState")}} object that represents the validity states this element is in.

Value

A {{domxref("ValidityState")}} object.

Example

The following example gets the validity state of a select element and processes it if it is not valid:

js
const select = document.getElementById("mySelect");
const validityState = select.validity;
if (!validityState.valid) {
  // Test each validity state
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also