<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("mySelect");
var option=document.createElement("option");
option.text="Kiwi";
try
{
// for IE earlier than version 8
x.add(option,x.options[null]);
}
catch (e)
{
x.add(option,null);
}
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
<br>
<button type="button" onclick="displayResult()">Insert option</button>
<p><b>Tip:</b> For the add() method to work properly in IE8 and higher, add a !DOCTYPE declaration to the page. Also notice the extra code for IE prior version 8.</p>
</body>
</html>