trying to insert select options with JS at run time.

O

onetitfemme

How come this works

http://www.geocities.com/tekmonk2005/testSelectJS00.html

works fine in Konqueror, but this

http://www.geocities.com/tekmonk2005/testSelectJS02.html

doesn't in FireFox, Internet Explorer and Opera (which apparently
tries to render two select boxes)?

The only difference is that in the second case the <select ...>
statement is included in the HTML code, in order to explicitily declare
the style right in the <select ...> statement (which is what I would
like to do), where as in the first case the "select" part is also
string'ed together as part of the options.

I would like to pass to the .innerHTML property the actual option
values of a form's select box.

How can you do that in a consistent/crossbrowser way?

otf
 
I

Ian Collins

onetitfemme said:
How come this works

http://www.geocities.com/tekmonk2005/testSelectJS00.html

works fine in Konqueror, but this

http://www.geocities.com/tekmonk2005/testSelectJS02.html

doesn't in FireFox, Internet Explorer and Opera (which apparently
tries to render two select boxes)?

The only difference is that in the second case the <select ...>
statement is included in the HTML code, in order to explicitily declare
the style right in the <select ...> statement (which is what I would
like to do), where as in the first case the "select" part is also
string'ed together as part of the options.

I would like to pass to the .innerHTML property the actual option
values of a form's select box.

How can you do that in a consistent/crossbrowser way?
Use DOM methods rather than innerHTML.

Also you should use type="text/javascript" rather than language="JavaScript.
 
R

RobG

onetitfemme said on 10/04/2006 6:20 AM AEST:
How come this works

http://www.geocities.com/tekmonk2005/testSelectJS00.html

works fine in Konqueror, but this

http://www.geocities.com/tekmonk2005/testSelectJS02.html

doesn't in FireFox, Internet Explorer and Opera (which apparently
tries to render two select boxes)?

The only difference is that in the second case the <select ...>
statement is included in the HTML code, in order to explicitily declare
the style right in the <select ...> statement (which is what I would
like to do), where as in the first case the "select" part is also
string'ed together as part of the options.

I would like to pass to the .innerHTML property the actual option
values of a form's select box.

How can you do that in a consistent/crossbrowser way?

The most cross-browser way to add options is to use new Option:

selRef(selRef.options.length) =
new Option([text, [value, [defaultSelected, [selected]]]])


Where all parameters are optional and:

text is the option text
value is the default value
selected is a boolean (true/false) to make the option selected
defaultSelected is a boolean to make the option the default selected

new Option() is DOM 0 and widely implemented, support is likely never to
be dropped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top