homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Trouble setting field.options[i].text in netscape 4
Does Nn4 = Js1.0?

10+ Year Member

Msg#: 369 posted 3:26 pm on Apr 16, 2003 (gmt 0)

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





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

Msg#: 369 posted 3:33 pm on Apr 16, 2003 (gmt 0)

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.


10+ Year Member

Msg#: 369 posted 3:39 pm on Apr 16, 2003 (gmt 0)

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


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

Msg#: 369 posted 9:37 pm on Apr 16, 2003 (gmt 0)

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.


WebmasterWorld Senior Member 10+ Year Member

Msg#: 369 posted 2:51 pm on Apr 17, 2003 (gmt 0)

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!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved