Option textProperty
Option Object
Definition and Usage
The text property sets or returns the text value of an option.
Tip:This property sets or returns the plain text contained in the <option> element. This text appears as the label of the option.
Syntax
Set the text property:
optionObject.text="text"
Return the text property:
optionObject.text
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the text property
Example
Example
The following example returns the text of all options in the dropdown list:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(selTag){
var x=selTag.options[selTag.selectedIndex].text;
alert("You selected: " + x);
}
</script>
</head>
<body>
<form>
Choose your favorite fruit:
<select onchange="displayResult(this)">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(selTag){
var x=selTag.options[selTag.selectedIndex].text;
alert("You selected: " + x);
}
</script>
</head>
<body>
<form>
Choose your favorite fruit:
<select onchange="displayResult(this)">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
</form>
</body>
</html>
Try it yourself »
More Examples
Output the text of all options in the dropdown list
Option Object Other Extensions