Table of Contents

Class HTMLSelectElement

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The HTMLSelectElement interface represents a {{HTMLElement("select")}} HTML Element. These elements also share all of the properties and methods of other HTML elements via the HTMLElement interface.

[Value("HTMLSelectElement")]
public class HTMLSelectElement : HTMLElement
Inheritance
HTMLSelectElement
Inherited Members

Remarks

-The select HTML element, which implements this interface.

See also on MDN

Constructors

HTMLSelectElement()

public HTMLSelectElement()

Properties

Autocomplete

The autocomplete property of the HTMLSelectElement interface indicates whether the value of the control can be automatically completed by the browser. It reflects the <select> element's autocomplete attribute.

[Value("autocomplete")]
public string Autocomplete { get; set; }

Property Value

string

A string representing the value of the autocomplete attribute ("on", "off", or a <token-list>) or the empty string ("") if unspecified.

Remarks

Disabled

The HTMLSelectElement.disabled property is a boolean value that reflects the
disabled
HTML attribute, which indicates whether the control is disabled. If it is disabled, it
does not accept clicks. A disabled element is unusable and un-clickable.

[Value("disabled")]
public bool Disabled { get; set; }

Property Value

bool

A boolean value.

Remarks

Form

The form read-only property of the HTMLSelectElement interface returns an HTMLFormElement object that owns this {{htmlelement("select")}}, or null if this select is not owned by any form.

[Value("form")]
public HTMLFormElement? Form { get; }

Property Value

HTMLFormElement

An HTMLFormElement or null.

Remarks

Labels

The HTMLSelectElement.labels read-only property returns a
NodeList of the {{HTMLElement("label")}} elements associated with the
select element.

[Value("labels")]
public NodeList Labels { get; }

Property Value

NodeList

A NodeList containing the <label> elements associated
with the <select> element.

Remarks

Length

The length property of the HTMLSelectElement interface specifies the number of {{htmlelement("option")}} elements in the {{htmlelement("select")}} element. It represents the number of nodes in the Options collection. On setting, it acts as (Length).

[Value("length")]
public ulong Length { get; set; }

Property Value

ulong

A number.

Remarks

Multiple

The multiple property of the HTMLSelectElement interface specifies that the user may select more than one option from the list of options. It reflects the {{htmlelement("select")}} element's multiple attribute.

[Value("multiple")]
public bool Multiple { get; set; }

Property Value

bool

A boolean.

Remarks

Name

The name property of the HTMLSelectElement interface indicates the name of the {{HTMLElement("select")}} element. It reflects the element's name attribute.

[Value("name")]
public string Name { get; set; }

Property Value

string

A string representing the element's name.

Remarks

Options

The HTMLSelectElement.options read-only property returns
a HTMLOptionsCollection of the {{HTMLElement("option")}} elements
contained by the select element.

[Value("options")]
public HTMLOptionsCollection Options { get; }

Property Value

HTMLOptionsCollection

A HTMLOptionsCollection containing the <option>
elements contained by the <select> element.

Remarks

Required

The required property of the HTMLSelectElement interface specifies that the user must select an option with a non-empty string value before submitting a form. It reflects the {{htmlelement("select")}} element's required attribute.

[Value("required")]
public bool Required { get; set; }

Property Value

bool

A boolean.

Remarks

SelectedIndex

The selectedIndex property of the HTMLSelectElement interface is the numeric index of the first selected {{HTMLElement("option")}} element in a {{HTMLElement("select")}} element, if any, or −1 if no <option> is selected. Setting this property selects the option at that index and deselects all other options, while setting it to -1 deselects any currently selected options.

[Value("selectedIndex")]
public long SelectedIndex { get; set; }

Property Value

long

A number.

Remarks

SelectedOptions

The read-only HTMLSelectElement property
selectedOptions contains a list of the
option elements contained within the select
element that are currently selected. The list of selected options is an
HTMLCollection object with one entry per currently selected option.

[Value("selectedOptions")]
public HTMLCollection SelectedOptions { get; }

Property Value

HTMLCollection

An HTMLCollection which lists every currently selected
HTMLOptionElement which is either a child of the
HTMLSelectElement or of an HTMLOptGroupElement within the
<select> element.In other words, any option contained within the <select> element may
be part of the results, but option groups are not included in the list.If no options are currently selected, the collection is empty and returns a
Length of 0.

Remarks

An option is considered selected if it has an Selected
attribute.

-Drop-down controls

See also on MDN

Size

The size property of the HTMLSelectElement interface specifies the number of options, or rows, that should be visible at one time. It reflects the {{htmlelement("select")}} element's size attribute. If omitted, the value is 0.

[Value("size")]
public ulong Size { get; set; }

Property Value

ulong

A number.

Remarks

NOTE

While by default a <select> displays a single row unless Multiple is true, in which case four rows are displayed, the default value for the size property is 0.

-select
-option
-SelectedOptions
-Length

See also on MDN

Type

The HTMLSelectElement.type
read-only property returns the form control's type.

[Value("type")]
public string Type { get; }

Property Value

string

One of the following:

Remarks

-The select HTML element, implementing this interface.

See also on MDN

ValidationMessage

The validationMessage read-only property of the HTMLSelectElement interface returns a string representing a localized message that describes the validation constraints that the {{htmlelement("select")}} control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation (WillValidate is false), or it satisfies its constraints.

[Value("validationMessage")]
public string ValidationMessage { get; }

Property Value

string

A string.

Remarks

If the <select> element is a candidate for constraint validation (willValidate is true) and the constraints are not met (the Validity object's valid property is false), the value is the error message that would be shown to the user during validation.

-select
-HTMLSelectElement
-WillValidate
-Validity
-CheckValidity()
-ReportValidity()
-SetCustomValidity(string)
-Learn: Client-side form validation
-Guide: Constraint validation
-CSS :valid and :invalid pseudo-classes

See also on MDN

Validity

The validity read-only property of the HTMLSelectElement interface returns a ValidityState object that represents the validity states this element is in.

[Value("validity")]
public ValidityState Validity { get; }

Property Value

ValidityState

A ValidityState object.

Remarks

Value

The HTMLSelectElement.value property contains the value of the first selected option element associated with this select element.

[Value("value")]
public string Value { get; set; }

Property Value

string

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

Remarks

This property can also be set directly, for example to set a default value based on some condition.

-The select HTML element, implementing this interface.

See also on MDN

WillValidate

The willValidate read-only property of the HTMLSelectElement interface indicates whether the {{htmlelement("select")}} element is a candidate for constraint validation. It is false if any conditions bar it from constraint validation, such as when its Disabled property is true.

[Value("willValidate")]
public bool WillValidate { get; }

Property Value

bool

A boolean value.

Remarks

Methods

Add(Union67, Union68?)

The HTMLSelectElement.add() method adds an element to the
collection of option elements for this select element.

[Value("add")]
public GlobalObject.Undefined Add(Union67 element, Union68? before = null)

Parameters

element Union67
before Union68?

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

CheckValidity()

The checkValidity() method of the HTMLSelectElement interface returns a boolean value which indicates if the element meets any constraint validation rules applied to it. If false, the method also fires an HTMLElementinvalid event on the element. Because there's no default browser behavior for checkValidity(), canceling this invalid event has no effect.

[Value("checkValidity")]
public bool CheckValidity()

Returns

bool

Returns true if the element's value has no validity problems; otherwise, returns false.

Remarks

NOTE

An HTML {{htmlelement("select")}} element with a non-null ValidationMessage is considered invalid, will match the CSS {{cssxref(":invalid")}} pseudo-class, and will cause checkValidity() to return false. Use the SetCustomValidity(string) method to set the ValidationMessage to the empty string to set the Validity state to be valid.

-ReportValidity()
-textarea
-form
-Learn: Client-side form validation
-Guide: Constraint validation
-CSS :valid and :invalid pseudo-classes

See also on MDN

NamedItem(string)

The HTMLSelectElement.namedItem() method returns the
HTMLOptionElement corresponding to the HTMLOptionElement
whose name or id match the specified name, or
null if no option matches.

[Value("namedItem")]
public HTMLOptionElement? NamedItem(string name)

Parameters

name string

Returns

HTMLOptionElement

An HTMLOptionElement or null.

Remarks

In JavaScript, using selectElt.namedItem('value') is equivalent to selectElt.options.namedItem('value').

-HTMLSelectElement that implements it.

See also on MDN

Remove()

The HTMLSelectElement.remove() method removes the element
at the specified index from the options collection for this select element.

[Value("remove")]
public GlobalObject.Undefined Remove()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

-Element.Remove, the method that gets called when remove is called
without arguments on a HTMLSelectElement.
-HTMLSelectElement that implements it.

See also on MDN

Remove(long)

The HTMLSelectElement.remove() method removes the element
at the specified index from the options collection for this select element.

[Value("remove")]
public GlobalObject.Undefined Remove(long index)

Parameters

index long

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

-Element.Remove, the method that gets called when remove is called
without arguments on a HTMLSelectElement.
-HTMLSelectElement that implements it.

See also on MDN

ReportValidity()

The reportValidity() method of the HTMLSelectElement interface performs the same validity checking steps as the CheckValidity() method. In addition, if the HTMLElementinvalid event is not canceled, the browser displays the problem to the user.

[Value("reportValidity")]
public bool ReportValidity()

Returns

bool

Returns true if the element's value has no validity problems; otherwise, returns false.

Remarks

SetCustomValidity(string)

The HTMLSelectElement.setCustomValidity() method sets the
custom validity message for the selection element to the specified message. Use the
empty string to indicate that the element does not have a custom validity
error.

[Value("setCustomValidity")]
public GlobalObject.Undefined SetCustomValidity(string error)

Parameters

error string

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

ShowPicker()

The HTMLSelectElement.showPicker() method displays the browser picker for a select element.

[Value("showPicker")]
public GlobalObject.Undefined ShowPicker()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

This is the same picker that would normally be displayed when the element is selected, but can be triggered from a button press or other user interaction.

-select
-HTMLSelectElement
-ShowPicker()

See also on MDN