|
HTML DOM add() Method
Complete Select Object Reference
Definition and Usage
The add() method is used to add an option to a dropdown list.
Syntax
|
selectObject.add(option,before)
|
| Parameter |
Description |
| option |
Required. Specifies the option to add. Must be an
option or optgroup element |
| before |
Required. Where to insert the new option (null
indicates that the new option will be inserted at the end of the
list) |
Example
The following example adds a "kiwi" option to the end of the dropdown list:
<html>
<head>
<script type="text/javascript">
function insertOption()
{
var y=document.createElement('option');
y.text='Kiwi'
var x=document.getElementById("mySelect");
try
{
x.add(y,null); // standards compliant
}
catch(ex)
{
x.add(y); // IE only
}
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" onclick="insertOption()"
value="Insert option" />
</form>
</body>
</html>
|
|
Try-It-Yourself Demos
Add an
option before 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.
|