Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Trouble setting field.options[i].text in netscape 4

Does Nn4 = Js1.0?

3:26 pm on Apr 16, 2003 (gmt 0)

10+ Year Member

i presume it is.. but was just wondering..



3:33 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Netscape 4 uses Javascript 1.2. Javascript 1.0 was introduced all the way back at Netscape 2.

I put together this handy reference for versions of javascript, jscript and ecmascript [webmasterworld.com] a while back. Hope it helps you.

3:39 pm on Apr 16, 2003 (gmt 0)

10+ Year Member

ok , in which case why can i not set the field.options[i].text value of a select in netscrape 4 then :(

from js book

in JS 1.0 text value of option is read only ..
in JS 1.1 and up it is settable.

or mbe im just missing something.. i am pretty knackered..

function clearselect(field){
for (i = field.options.length; i >= 0; i--) {
if(isNN == true){
field.options[i].text = '';
field.options[i] = null;

as you may have found. doing this .. when i want to refill the field, NN4 gives the depth of the dropdowns no depth..
something that im missing?!

cheers again

9:37 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The problem (in this case) is the actual value of the variable "field". For NN4 it works best with document.layers... For IE4 it's document.all... For more recent browsers you should use document.getElementById...

Or, whenever possible use the universal this to pass the correct value for each individual browser.

2:51 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I'm obviously coming in late to this discussion, but to my knowledge, NS4 doesn't behave any differently than any other browser when it comes to <form> elements. Are you sure your test that sets the variable "isNN" is detecting only NS4 and not NS v6.x+?

In any case, your sample code looks like it is attempting to modify only the VALUE of a form's <OPTION>. DrDoc is probably on the right path when he suggests you really need to modify the innerHTML/layer contents entirely so not only will the <OPTION> value be updated, the user will see the new value in the OPTIONs list on the page as well. Sadly, in NS4, this can only be done in a absolutely-positioned <DIV>. I use code like this to write HTML:

function writeMe(theWindow,id,theText) {

if (document.getElementById) { // NS6+, IE5.5+
theWindow.document.getElementById(id).innerHTML = theText;
} else if (document.all) { // IE4+
theWindow.document.all[id].innerHTML = theText;
} else if (document.layers) { // NS4 ONLY!
theElement = theWindow.document.layers[id].document;
theElement.open(); // open document
theElement.write(theText); // write to document
theElement.close(); // close document
} // endif browser branches

} // end writeMe

So, you'd be setting theText to something like:

theText = "<option value=\"" + newValue + "\">" +
newOptionLabel + "</option>";

and then call writeMe(); with the appropriate values. Good luck!


Featured Threads

Hot Threads This Week

Hot Threads This Month