0

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

1
  • 2
    Please add some surrounding code. What is ship_modeId, selcted, and Option? Commented Nov 8, 2010 at 18:46

3 Answers 3

2

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

Use this,

var drpDown = document.getElementById("shipModeId_1");
drpDown.options[drpDown.options.length] = new Option(ship_modeId,selcted);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.