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 Demos
Output the text of all options in a dropdown list
Set
the text of a selected option in a dropdown list
Complete Select Object Reference
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
Request an INSTANT DEMO or download a FREE TRIAL today. |
|
|
|