Menu DHTML script problems - timer, setTimeout, openMenu(id)

Posted on 2007-10-12
Last Modified: 2013-11-19
I am having problems with DHTML for my menu system.
The problem is:

  1. Go to
  2. Hover your mouse over menu items on left (Home Owners and Products)
  3. Quickly hover over 'Products' THEN continue down to 'Home Owners'.
  4. Note that one of the menu systems stays open.

You can view the script that makes this happen at:
  * View Page Source - to see what methods are called on the menu.

I am think this may has something to do with using a commonly declared timer. The timer is reset in the openMenu(id) call and that stops the other menu closing. The problem is I cannot find a solution.

Question by:smacca
    LVL 23

    Accepted Solution

    replace your existing menu.js with this code:


    var timeout = 500; //in milliseconds.


    //open menu

    function openMenu(id)


        //cancel close timers.



        //close old layer



        //get new layer and show it.    



    //close menu

    function closeMenu(id)




    var timers=new Object();

    //close timer

    function closeMenuTimer(id)


        timers[id] = window.setTimeout(function(){closeMenu(id)}, timeout);


    //cancel close timer

    function cancelCloseMenuTimer(id)


        if (timers[id])



            timers[id] = 0;



    Author Comment

    Thanks BasicInstinct!

    You fixed the problem (I will award points for regardless), however, a new problem has been introduced:

    The menu does not STAY OPEN when you mouseover a submenu item.
    Could you help here at all???


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now