View Full Version : 2 Scripts on a page dont like eachother

08-05-2006, 01:23 PM
ok so i have this problem where i have downloaded a contractable headers script... and a chained dropdown list although the chained dropdown list wont display its information and the dropdown headers dont work when they are together.

Oddly enough they seem to work together in firefox? but IE, Opera, and NS all dont want to work.

Heres an example link: http://www.extremealcohol.com/index.php?id=search&c=7
Its the same on quite a few pages. (well where there is a dropdown list)

Any help here is apreciated. :thumbsup:

08-05-2006, 01:41 PM
I suspect this:

1.the code in menu. js is made to work only for IE/Opera (as in Moz it can be done with CSS only)
2. both codes use onload event, and onload, as a window's event, is to be used only once in a page/session.

Now, in your menu.js you have
window.onload = init;
in your body you have also an onload
<body onload="initListGroup('homebrew', document.forms[0].s1, document.forms[0].s2)">

To solve the problem you have to combine the triggered functions onto a single onload call. For instance, remove the onload from body tag, and move that function into the init() function (in menu.js)

function init(){
initListGroup('homebrew', document.forms[0].s1, document.forms[0].s2);
menu = getElementsByClassName("sdmenu", "div", document)[0];
titles = getElementsByClassName("title", "span", menu);
submenus = getElementsByClassName("submenu", "div", menu);
arrows = getElementsByClassName("arrow", "img", menu);
for(i=0; i<Math.max(titles.length, submenus.length); i++) {
titles[i].onclick = gomenu;
arrows[i].onclick = gomenu;
heights[i] = submenus[i].offsetHeight;
submenus[i].style.height = submenus[i].offsetHeight+"px";
if(remember) restore();

Or call the init function from body, and remove the onload from menu.js. Or remove the onload handlers from both places and create an new separate onload.js file, and call both function there (my favourite solution)

in onload.js

onload = function(){
initListGroup('homebrew', document.forms[0].s1, document.forms[0].s2);

Thus you may have a direct control to all the functions which might needed to be triggered onload.