|
HTML DOM options Collection
Complete Select Object Reference
Definition and Usage
The option collection returns an array of all the options in a dropdown list.
Note: There is one element for each <option> tag - starting at 0.
Syntax
Example
The following example outputs the text of all the options in the dropdown
list:
<html>
<head>
<script type="text/javascript">
function getOptions()
{
var x=document.getElementById("mySelect");
txt="All options: "
for (i=0;i<x.length;i++)
{
txt=txt + "\n" + x.options[i].text;
}
alert(txt);
}
</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="getOptions()"
value="Output all options">
</form>
</body>
</html>
|
|
Try-It-Yourself Demo
Set
the text of a selected option in a dropdown list
Complete Select Object Reference
729,913 sites built with Wix. Make your own
Click here to design a Stunning Flash Website for Free
Wix is a revolutionary web design tool that provides anyone with the possibility to create professional and beautiful websites for free.
With e-commerce features, search engine visibility and many more professional tools, Wix is the ultimate solution for creating a spectacular site while saving tons of money.
|