Link to home
Start Free TrialLog in
Avatar of pacchy
pacchy

asked on

Adding an option to the combo box when it is empty (differs in IE5 and IE5.5)

IN HTML
I am creating an object opt1 as below
opt1 = document.createElement("OPTION")
and I am assigning text and value to the object opt1.
opt1.text = "name";
opt1.value = "1234";

Then I am adding this as an option in a combobox.
combo1.options.add(opt1);

If the combo1 is empty, in Internet Explorer 5 this addtion will result in one option added in the combobox.

If the combo1 is empty, the same piece of code adds two options of the same text and values in Internet Explorer 5.5.

Can any body help in resolving this.
Avatar of CJ_S
CJ_S
Flag of Netherlands image

Resolve way:

obj = document.forms["formname"]["selectobject"];
obj[obj.length] = new Option("text", "value");

CJ
CJ to get that to work I think you have to pre-define size either with
a size attribute on the select or like this

obj = document.forms["formname"]["comboname"];
obj.size=1;
obj[obj.length] = new Option("text", "value");

Otherwise length is either -1 or undefined.  I'm not sure which, but
it does not work until I sized.

pacchy,

your code work for me in IE5.5 are you sure that you only
populating once.

To confirm, I set it up with size="2" and when I added the option it added
just one.

when I don't size it, is start out a tiny size and when I add the option
it adds it just once.

Cd&
Avatar of pacchy
pacchy

ASKER

I got it resolved the problem was that i should not add the text and value before adding the opt1...
thanks
This question has been abandoned.  I will make a recommendation to the
moderators on its resolution in a week or two.  I appreciate any comments
that would help me to make a recommendation.

Cd&
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial