[thelist] [DOM] Dynamically adding an OPTION to SELECT - funky IE vs Gecko...

Tom Dell'Aringa pixelmech at yahoo.com
Tue Mar 16 08:17:42 CST 2004

--- Kasimir K <mail at kasimir-k.fi> wrote:

> however, you can not:
> option.text = arrayOptions[1][i];
> because 'text' is readonly attribute ('form' and 'inxed' are
> readonly too).

Actually, I can do that (and AM doing that) :). Not sure where you
are getting that info from, but options[index].text is a read/write

Now that I think about it, the only DOM way to do the value would be
to use setAttribute() which isn't well supported, so option.text is
the only way to go.

Works fine across IE and Gecko browsers - even Opera likes it! ;)


P.S Final code block that works:

for(var i=0; i<arrayLength; i++)
   option = document.createElement("OPTION");
   option.value = arrayOptions[0][i];
   option.text = arrayOptions[1][i];

http://www.Pixelmech.com/ - read my latest blog posting!
http://www.DMXzone.com/ - JavaScript Author
http://SparklesParties.com - Princess parties for little girls!
http://www.thywordistruth.net/ - Eternal Life

"Well, my name's Dewey Oxburger. My friends call me Ox. I dont know if you've noticed, but I got a slight weight problem."

More information about the thelist mailing list