Forum Moderators: not2easy

Message Too Old, No Replies

hiding a div not working in Netscape

referencing a div id is not working in Netscape

         

garydr

2:53 am on Feb 11, 2004 (gmt 0)

10+ Year Member



I have a web page which uses JavaScript to change the style assigned to a div. Initially the div has a style assigned to it to make it hidden. Here is the div code with the style code as well.

.dnone {display: none;}
<div id="d11" class =' dnone' ><img src="../product_images/" width="1" height="5"><table cellpadding="0" cellspacing="0" width =" 700"><tr ><td align="left" width="450"> <label id="l11">inp11Choose method of attaching vellum.</label>&nbsp;<select id=" inp11" name=" inp11" onChange="Process(this.selectedIndex, '12¦13¦14¦', 11)"> <option value = NULL > Please select</option><option value="768">Satin Ribbon</option><option value="769">Specialty Ribbon</option><option value="774">Eyelets or Hearts</option></select><input TYPE=hidden NAME=hid_op_choice11 VALUE=""> <input TYPE=hidden NAME=hid_op_desc11 VALUE=""> <input TYPE=hidden NAME=hid_OG11 VALUE="30"> <input TYPE=hidden NAME=hid_M11 VALUE="N"> <input TYPE=hidden NAME=hid_price11 VALUE="0"> <input TYPE=hidden NAME=hid_vis11 ID=hid_vis11 VALUE="hide"> </td></tr></table><img src="../product_images/" width="1" height="5"></div>

When another drop down selection is made, it triggers the javascript "Process" which will assign a new style to make the div visible. A javascript code fragment is:

var evstring ="d"+ n +".className ='dblock'";
eval(evstring);

n previously was evaluated to 11 so that
evstring = "d11.className ='dblock'"

In IE or Safari, this works fine, but in Netscape 7.02 on a Mac ( I haven't tried Windows) I get an error message as follows:

Error: d11 is not defined.

And it points to the eval statement. Well, d11 does indeed exist. Can anyone explain why this doesn't work in Netscape?

Thanks.

Purple Martin

5:31 am on Feb 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need a full reference to the div object. IE is forgiving (sloppy?) and assumes it knows what you meant and corrects your mistake, Netscape etc do things properly and let you know where you went wrong.

For Netscape etc you need to make
evstring = 'document.getElementById("d11").className ="dblock"'
(NB: I switched the quotes)

For IE it should really be
evstring = 'document.all["d11"].className ="dblock"'
(NB: the brackets are square for IE)

garydr

3:10 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



Purple Martin, you are my hero! I have struggled with this for sooo long. Thanks very much.