Option selected Property
Option Object
Definition and Usage
The selected property sets or returns the value of the selected attribute of an option.
Syntax
Set the selected property:
optionObject.selected=true|false
Return the selected property:
Browser Support

The selected property is supported in all major browsers.
Example
Example
Change the selected option in a dropdown list:
<html>
<head>
<script>
function displayResult()
{
document.getElementById("orange").selected=true;
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select>
<option id="apple">Apple</option>
<option id="orange">Orange</option>
<option id="pineapple" selected="selected">Pineapple</option>
<option id="banana">Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">Select Orange</button>
</body>
</html>
Try it yourself »
Option Object
Thank You For Helping Us!
Your message has been sent to W3Schools.
Close [X]