Easy Tutorial
❮ Jsref Getseconds Prop Nav Appname ❯

defaultSelected Attribute


Definition and Usage

The defaultSelected attribute returns the initial value of the selected attribute.

It returns true if the default option is selected, otherwise it returns false.

If the form is reset, the selected attribute is reset to the value of this attribute. This attribute also sets the value of the selected attribute.

Note: The default option will be displayed first.

Syntax


Browser Support

All major browsers support the defaultSelected attribute.


Example

The following example checks if the selected option is the default option:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
<script>
function displayResult(){
    var x=document.getElementById("mySelect").selectedIndex;
    var y=document.getElementsByTagName("option");
    alert("" + y[x].text + " is the default option? " + y[x].defaultSelected);
}
</script>
</head>
<body>

<form>
Select your favorite fruit:
<select id="mySelect">
    <option>Apple</option>
    <option>Orange</option>
    <option selected="selected">Pineapple</option>
    <option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">Is the selected fruit the default?</button>

</body> 
</html>

❮ Jsref Getseconds Prop Nav Appname ❯