Reputation: 3027
I have a js function which is called onchange of a drop-down. It works in FF, IE6 and 7 and Safari. In IE8 however the function breaks at the following line.
document.getElementById("shipModeId_1").options[document.getElementById("shipModeId_1").options.length]
= Option(ship_modeId,selcted);
It says Object doesn't support this property or method. Any idea why this is happening?
Thanks,
Sarego
Upvotes: 0
Views: 638
Reputation: 1682
Use this,
var drpDown = document.getElementById("shipModeId_1");
drpDown.options[drpDown.options.length] = new Option(ship_modeId,selcted);
Upvotes: 0
Reputation: 536379
You missed the new
operator. Also you probably want to pass in the same value for the text
and the value
arguments, with selected
following that. The two-argument form of the Option
constructor takes text
and value
, not selected
.
new Option(ship_modeId, ship_modeId, selected)
Upvotes: 2
Reputation: 114367
If this is for a <select>
, I don't think you need "options".
document.getElementById("shipModeId_1")[document.getElementById("shipModeId_1").length] = new Option(ship_modeId,selcted);
You also missed "new" in generating the new option.
Upvotes: 0