Results 1 to 10 of 10

Thread: concepts but no solution for multiple javascripts

  1. #1
    Join Date
    Mar 2007
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default concepts but no solution for multiple javascripts

    1) Script Title: slashdot menu

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

    3) Describe problem:
    trying to resolve the advice I've found for using body onload to include multiple javascript menus on one page. Not directly a slashdot menu problem, but needing a solution to getting two functions from the script sample below into the body onload - the example being: <body onload="shake (); Delay()">

    I want two menus on the page, one on right and the other on the left-hand column.
    one i can call "left_menu", the other I'll call "right_menu"

    <script type="text/javascript">
    // <![CDATA[
    var myMenu;
    window.onload = function() {
    myMenu = new SDMenu("left_menu"); // ID of the menu element
    // Default values...
    myMenu.speed = 3; // Menu sliding speed (1 - 5 recomended)
    myMenu.remember = false; // Store menu states (expanded or collapsed) in cookie and restore later
    myMenu.oneSmOnly = true; // One expanded submenu at a time
    myMenu.markCurrent = true; // Mark current link / page (link.href == location.href)
    myMenu.collapseAll(); // Collapse all submenus

    myMenu.init();
    };
    // ]]>
    </script>
    Last edited by tmate; 11-21-2008 at 02:11 AM. Reason: clarify

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    This should do it:
    Code:
    <script type="text/javascript">
    // <![CDATA[
    var myMenu;
    window.onload = function() {
    myMenu = new SDMenu("left_menu"); // ID of the menu element
    // Default values...
    myMenu.speed = 3; // Menu sliding speed (1 - 5 recomended)
    myMenu.remember = false; // Store menu states (expanded or collapsed) in cookie and restore later
    myMenu.oneSmOnly = true; // One expanded submenu at a time
    myMenu.markCurrent = true; // Mark current link / page (link.href == location.href)
    myMenu.collapseAll(); // Collapse all submenus
    
    myMenu.init();
    };
    
    var mySecondMenu;
    window.onload = function() {
    mySecondMenu = new SDMenu("right_menu"); // ID of the menu element
    // Default values...
    mySecondMenu.speed = 3; // Menu sliding speed (1 - 5 recomended)
    mySecondMenu.remember = false; // Store menu states (expanded or collapsed) in cookie and restore later
    mySecondMenu.oneSmOnly = true; // One expanded submenu at a time
    mySecondMenu.markCurrent = true; // Mark current link / page (link.href == location.href)
    mySecondMenu.collapseAll(); // Collapse all submenus
    
    mySecondMenu.init();
    };
    // ]]>
    </script>
    Jeremy | jfein.net

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There can only be one window.onload - the second one will override the first. And if there is also a body onload event in the body tag after that, it will override the second one.

    Use addEventListener/attachEvent instead.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I guess this would work then:
    Code:
    <script type="text/javascript">
    // <![CDATA[
    var myMenu;
    var wO = function(){
    myMenu = new SDMenu("left_menu"); // ID of the menu element
    // Default values...
    myMenu.speed = 3; // Menu sliding speed (1 - 5 recomended)
    myMenu.remember = false; // Store menu states (expanded or collapsed) in cookie and restore later
    myMenu.oneSmOnly = true; // One expanded submenu at a time
    myMenu.markCurrent = true; // Mark current link / page (link.href == location.href)
    myMenu.collapseAll(); // Collapse all submenus
    
    myMenu.init();
    };
    
    var mySecondMenu;
    var wOO = function() {
    mySecondMenu = new SDMenu("right_menu"); // ID of the menu element
    // Default values...
    mySecondMenu.speed = 3; // Menu sliding speed (1 - 5 recomended)
    mySecondMenu.remember = false; // Store menu states (expanded or collapsed) in cookie and restore later
    mySecondMenu.oneSmOnly = true; // One expanded submenu at a time
    mySecondMenu.markCurrent = true; // Mark current link / page (link.href == location.href)
    mySecondMenu.collapseAll(); // Collapse all submenus
    
    mySecondMenu.init();
    };
    if (window.addEventListener){
      window.addEventListener('load', wO, false);
      window.addEventListener('load', wOO, false); 
    } else if (el.attachEvent){
      window.attachEvent('load', wO);
      window.attachEvent('load', wOO);
    }
    
    // ]]>
    </script>
    Jeremy | jfein.net

  5. #5
    Join Date
    Mar 2007
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default yes indeed!

    thank you
    thank you
    wow....

  6. #6
    Join Date
    Mar 2007
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    the javascript for the multiple menus worked great in Firefox but not in IE! Neither menu will work...
    any suggestions? Here is the page i'm working with:

    http://www.santaritasteel.com/catalog.html

    thank you...
    Teri
    Last edited by tmate; 11-22-2008 at 08:14 AM. Reason: clarify

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The attachEvent syntax is wrong. This:

    Code:
      window.attachEvent('load', wO);
      window.attachEvent('load', wOO);
    should be:

    Code:
      window.attachEvent('onload', wO);
      window.attachEvent('onload', wOO);
    There could possibly be other issues. But that much must be fixed first. It may be the only problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2007
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default must be something else too

    with this corrected, the menus (both) are not operating in IE

    mySecondMenu.init();
    };
    if (window.addEventListener){
    window.addEventListener('load', wO, false);
    window.addEventListener('load', wOO, false);
    } else if (el.attachEvent){
    window.attachEvent('onload', wO);
    window.attachEvent('onload', wOO);
    }

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Nile was really sloppy on this one, there is another problem, should be:

    Code:
    mySecondMenu.init();
    };
    if (window.addEventListener){
    window.addEventListener('load', wO, false);
    window.addEventListener('load', wOO, false); 
    } else if (window.attachEvent){
    window.attachEvent('onload', wO);
    window.attachEvent('onload', wOO);
    }
    Last edited by jscheuer1; 11-22-2008 at 06:19 PM. Reason: spelling
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. The Following User Says Thank You to jscheuer1 For This Useful Post:

    tmate (11-22-2008)

  11. #10
    Join Date
    Mar 2007
    Posts
    28
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default whew!

    again... many thanks... that was it!.. el is not a useful syntax element!
    your help is very very much appreciated

Bookmarks

Posting Permissions

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