Option defaultSelected Property
Example
Check if the selected option is checked by default:
var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementsByTagName("option");
alert("Is " + y[x].text + " selected by default? " + y[x].defaultSelected);
Try it Yourself »
Description
The defaultSelected property returns the default value of the selected attribute.
This property returns true if an option is selected by default, otherwise it returns false.
Note: If an option is selected by default, it is displayed first in the drop-down list.
Browser Support
Property | |||||
---|---|---|---|---|---|
defaultSelected | Yes | Yes | Yes | Yes | Yes |
Syntax
optionObject.defaultSelected
Technical Details
Return Value: | A Boolean, returns true if the option is selected by default, otherwise it returns false |
---|
❮ Option Object