PDA

View Full Version : concepts but no solution for multiple javascripts



tmate
11-21-2008, 02:09 AM
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>

Nile
11-21-2008, 04:12 AM
This should do it:


<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>

jscheuer1
11-21-2008, 04:26 AM
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.

Nile
11-21-2008, 12:47 PM
I guess this would work then:


<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>

tmate
11-21-2008, 01:58 PM
thank you
thank you
wow....

tmate
11-22-2008, 08:09 AM
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

jscheuer1
11-22-2008, 09:16 AM
The attachEvent syntax is wrong. This:


window.attachEvent('load', wO);
window.attachEvent('load', wOO);

should be:


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.

tmate
11-22-2008, 02:00 PM
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);
}

jscheuer1
11-22-2008, 02:51 PM
Nile was really sloppy on this one, there is another problem, should be:


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);
}

tmate
11-22-2008, 03:16 PM
again... many thanks... that was it!.. el is not a useful syntax element!
your help is very very much appreciated:D:)