...

View Full Version : display:none won't work in Netscape



Frank
09-24-2003, 07:26 PM
I have gotten display:none to work in NN using html but I need it to change between none and inline using javascript. The following code works great in IE but not in NN.


<style type="text/css">
#table_menu1 {display:none}
#table_menu2 {display:none}
#table_menu3 {display:none}
#table_menu4 {display:none}
#table_menu5 {display:none}
#table_menu6 {display:none}
#table_menu7 {display:none}
#table_menu8 {display:none}
#table_menu9 {display:none}
</style>

<script>
var i;
var tm = new Array(8);
for(i=0; i<=7; i++){
tm[i]=true;
}

function OpenSubMenu(divnum,menu){
if (tm[divnum]==true){
eval ("document.getElementById('"+ menu +"').style.display = 'none'");
tm[divnum]=false;
}else if (tm[divnum]==false){
eval ("document.getElementById('"+ menu +"').style.display = 'inline'");
tm[divnum]=true;
}
}
</script>

Choopernickel
09-24-2003, 07:36 PM
What version of NetNanny?

Seriously, which version of (I assume you mean) Netscape?

I've had no problems using display: none; or visibility: hidden in any of the Gecko browsers.

You've got a serious no-no in your code, though:

eval ("document.getElementById('"+ menu +"').style.display = 'none'");
// ...
eval ("document.getElementById('"+ menu +"').style.display = 'inline'");

really should be


document.getElementById(menu).style.display = 'none';
// ...
document.getElementById(menu).style.display = 'inline';

eval() is evil! There are plenty of reasons all over this forum as to why; for your usage, it's completely unnecessary.

Frank
09-24-2003, 07:58 PM
There is nothing evil about eval() if you know of a better way to pass info from a function into a string I would like to hear it.

I sorry if I wasn't clear enough, but the code that I have works just like I want it to in Internet Explorer, but in Netscape Navigator it only changes the display from none to inline. It won't change it back.

I didn't post the the whole htm because its to long theres just no need the however i am using an onClick to call the function that looks like this.

onClick="OpenSubMenu('0','table_menu1')"

Hope someone out there can help.:(

Frank
09-24-2003, 08:43 PM
I figured out the problem, though it doesn't make much sense.

I took out the inline from the line of javascript so it now looks like this.

<script>
var i;
var tm = new Array(9);
for(i=0; i<=8; i++){
tm[i]=false;
}

function OpenSubMenu(divnum,menu){
if (tm[divnum]==true){
eval ("document.getElementById('"+ menu +"').style.display = 'none'");
tm[divnum]=false;
}

else if (tm[divnum]==false){
eval ("document.getElementById('"+ menu +"').style.display = ''");
tm[divnum]=true;
}
}
</script>

I got rid of the embedded css and just put the style="display:none" in the divs that I whated to change the display for. Oh ya and those <div>s use to be <span>s. Sort of strange but whatever.

liorean
09-24-2003, 08:48 PM
There is very much evil in eval. Search the forums for those two words and you'll soon find an explanation. In your case, eval ("document.getElementById('"+ menu +"').style.display = 'none'"); could be rewritten to document.getElementById(menu).style.display='none';

Frank
09-24-2003, 09:11 PM
I have tried the code you guys have been suggesting

document.getElementById(menu).style.display='none');

and it just doesn't work. I'm using

eval ("document.getElementById('"+ menu +"').style.display = 'none'");

because I have several <div>s that I want to change i'm passing the divs id, when I call it instead of using a different function for each one.

I did do a search and could find no valid reason to stop using eval. I think that eval() has gotten a bad reputation.

liorean
09-24-2003, 09:28 PM
Eval's got a bad reputation, all right, but it's not a reputation that it hasn't earned. Some of the reputation comes from more potent languages than clientside javascript, but it is still a last resort at best.

You see, the evil of eval stems from that eval requires very much of the language, that can be done far easier in almost all cases. Eval is a resource hog, requiring a language implementation to have it inevitable taxes the implementation much and reduces the top speed of it, thus it's the true bottleneck of a language implementation. Using eval also means that you're making the engine do much more htan double work, and that makes your script take much more resources than necessary from the comp, which means that you are affecting the resources avalable for other programs and utilities. For example even a short a loop containing eval could tax the system so much that a music player would be unable to decode mp3s without interuptions, and that is only the most obvious of things that happen. This is especially true of iew on win9x where a well (read: ill) constructed javascript can actually crash the operative system. This is true for other cases than eval, but eval is the worst of them.

Not to speak of the fact that eval gets misused so much, in cases like the one you have there. That is a case where there is absolutely no reason for eval - it's just superflous.

Choopernickel
09-24-2003, 09:47 PM
Thanks for getting my back there, liorean.

I screwed up my UBB tags up there; I'll fix those.

Your blue fix, which echoes my [code] fix, has an extra parin at the end of it.

I left off a comma.


eval() is evil like the devil.

liorean
09-24-2003, 10:07 PM
Oh, that paren was left there by mistake. It shouldn't be there, really.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum