HTML DOM text Property
Complete Option Object Reference
Definition and Usage
The text property sets or returns the text value of an option.
Syntax
optionObject.text=sometext
|
Example
The following example returns the text of the selected option:
<html>
<head>
<script type="text/javascript">
function getOption()
{
var x=document.getElementById("mySelect")
alert(x.options[x.selectedIndex].text)
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getOption()"
value="Alert text of selected option">
</form>
</body>
</html>
|
Try-It-Yourself Demos
Return the text of a selected option in a dropdown list
Set
the text of a selected option in a dropdown list
Complete Option Object Reference
Want To Be A Web Master?
If you want to be a Web Master, you will have to host your web site with an ISP (Internet Service Provider).
MaximumASP offers seven different configurations of dedicated servers to meet your Windows and .NET hosting needs.
Hosted on our multi-tiered Enterprise Class network, these servers provide the performance, security and reliability
you need to host your high end web sites and applications.
Visit MaximumASP
|