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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Post 2 Scripts on a page dont like eachother

    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.
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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)

    Code:
    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
    Code:
    onload = function(){
    initListGroup('homebrew', document.forms[0].s1, document.forms[0].s2);
    init();
    }
    Thus you may have a direct control to all the functions which might needed to be triggered onload.
    Last edited by Kor; 08-05-2006 at 01:44 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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