selected property (option)
Sets or retrieves the state of an option element.
If you need to detect when an option becomes selected, or in other words, when the selection has changed in a select element, use the onchange event.
The select element allows simple or multiple selection, depending on the state of the multiple property.In a non-empty drop-down list always exactly one selected element exists. If there is no element selected by default in a drop-down list, the first option will be selected.
- If multiple selection is allowed, the visual appearance of the selection list can only be a list box.
- If only one selected element is allowed, the selection list may be a drop-down list or a list box. The default appearance is the drop-down list.
If the value of the size property is greater than one, the appearance of the selection list is a list box.
In a single-selection list box the count of the selected items can be 0 (if the list box has no selected element by default) or 1.
In a multiple-selection list box the count of the selected items may range from 0 to the number of the items.
You can find the related objects in the Supported by objects section below.
This property is read/write.
|HTML page for this property: SELECTED|
Boolean that indicates the selected state of the object.
One of the following values:
|The option is not selected.|
|The option is selected.|
Example HTML code 1:
This example illustrates the use of the SELECTED attribute in a single-selection list:
Example HTML code 2:
This example illustrates the use of the SELECTED attribute in a multiple-selection list:
Example HTML code 3:
This example illustrates the use of the selected property in a multiple-selection list:
Example HTML code 4:
This example displays the text of the selected items in a multiple-selection list:
Example HTML code 5:
This example is similar to the previous one but it displays the value of the selected items in a multiple-selection list:
User Contributed Comments