X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Option selected Property

Option Object Reference Option Object

Example

Change the selected option in a drop-down list to "orange":

document.getElementById("orange").selected=true;

Try it yourself »


Definition and Usage

The selected property sets or returns the selected state of an option.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The selected property is supported in all major browsers.


Syntax

Return the selected property:

optionObject.selected

Set the selected property:

optionObject.selected=true|false

Property Values

Value Description
true|false Specifies whether an option in a drop-down list should be selected or not.
  • true - The option is selected
  • false - Default. The option is not selected

Technical Details

Return Value: A Boolean, returns true if the option is selected, otherwise it returns false


More Examples

Example

Find out if the "banana" option in a drop-down list is selected or not:

var x = document.getElementById("banana").selected;
document.getElementById("demo").innerHTML=x;

Try it yourself »


Related Pages

HTML reference: HTML <option> selected attribute


Option Object Reference Option Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook