Javascript dropdown menu

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
Najjar
Posts: 2
Joined: Tue 16. Aug 2005, 15:13

Javascript dropdown menu

Post by Najjar »

Hi,
I am new to this forum; I am using the (CSS, Javascript) Menu
that you have in this forum: http://www.phpwcms.de/forum/viewtopic.php?p=27079

I need to use onclick event instead of (onmouseover & onmouseout)
so I was able to use onclick to show and ondblclick to hide the menu
but I want only onclick to be used to (show and hide); according to the
code you have to use two different events to do that.

Any help would be appreciated.
Thank you in advance.
Najjar
Najjar
Posts: 2
Joined: Tue 16. Aug 2005, 15:13

Post by Najjar »

I think I found the solution :)
Thank you all
Solution:

Code: Select all

activateMenu = function(nav) {

    /* currentStyle restricts the Javascript to IE only */
	if (document.all && document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */
        var lis=navroot.getElementsByTagName("LI");

        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */

             	lis[i].onclick=function() {
		this.lastChild.style.display = (this.lastChild.style.display == 'block') ? 'none' : 'block'; 
                }

	    }
            
        }
    }
}
Najjar
Post Reply