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 »
Definition and Usage
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
The defaultSelected property is supported in all major browsers.
Syntax
optionObject.defaultSelected
Technical Details
Return Value: | A Boolean, returns true if the option is selected by default, otherwise it returns false |
---|
Option Object