Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 1 Time in 1 Post

    display:none won't work in Netscape

    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>
    if ( atfirst != succeed)
    tryagain();

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    eval ("document.getElementById('"+ menu +"').style.display = 'none'"); 
    // ... 
    eval ("document.getElementById('"+ menu +"').style.display = 'inline'");
    really should be

    Code:
    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.
    Last edited by Choopernickel; 09-24-2003 at 08:48 PM.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    if ( atfirst != succeed)
    tryagain();

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 1 Time in 1 Post

    Cool got the solution

    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.
    if ( atfirst != succeed)
    tryagain();

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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';
    Last edited by liorean; 09-24-2003 at 09:02 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Regular Coder
    Join Date
    Dec 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 1 Time in 1 Post

    hear no eval, speak no eval, see no eval

    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.
    if ( atfirst != succeed)
    tryagain();

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Oh, that paren was left there by mistake. It shouldn't be there, really.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •