473,765 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a parent node clickable in a collapse menu

3 New Member
Hello,
I download a nice collapse menu for free distribution from the internet. It works very well except that none of the parents nodes are clickable (i.e. when clicking on the parent node, the link does not work). For example, if the below content is included in the html page, I would like that page www.fruit.com can be loaded whenever I click it. However the javascript does not allow the page to be loaded, It would only work for the child nodes apple, orange and pear.
Expand|Select|Wrap|Line Numbers
  1. <div id="leftcolumn"> 
  2. <ul id="menu">
  3.     <li> <a href="http://www.fruit.com"><b>> Fruits</b></a>
  4.         <ul>
  5.                                        <li><a href="#">>> apple</a></li>
  6.                              <li><a href="#">>> orange </a></li>
  7.                <li><a href="#">>> pear </a></li>
  8. </ul>
  9. </li> 
  10. </ul>
  11. </div>
  12.  
I have been trying to figure out the reason of this during three days with no success. My background in programming is not very strong so I'd appreciate all your help on this.



The java script is as follows:
Expand|Select|Wrap|Line Numbers
  1. function collapseMenu(node) {
  2.     if (!document.getElementById) return false;
  3.     if (!document.getElementById("menu")) return false;
  4.     if (!node) node = document.getElementById("menu");
  5.  
  6.     if (node.childNodes.length > 0) {
  7.         for (var i=0; i<node.childNodes.length; i++) {
  8.             var child = node.childNodes[i];
  9.             if (child.nodeName == "UL") {
  10.                     child.style.display = "none";
  11.             }
  12.             collapseMenu(child);
  13.         }        
  14.     }
  15.  
  16. }
  17.  
  18. function prepareMenu() {
  19.     if (!document.getElementById || !document.getElementsByTagName) return false;
  20.     if (!document.getElementById("menu")) return false;
  21.  
  22.     var links = document.getElementById("menu").getElementsByTagName("a");
  23.     for (var i=0; i<links.length; i++) {        
  24.         links[i].onclick = function() {
  25.             toggleMenu(this.parentNode.getElementsByTagName("UL")[0], this.href);
  26.             return false;
  27.         }
  28.     }
  29. }
  30.  
  31. function toggleMenu(node, link) {
  32.     if (!document.getElementById) return false;
  33.     if (!link) return false;
  34.     if (!node) location.href = link.href;
  35.  
  36.     // Collapse all nodes, and only show clicked node (when clicking top level of menu)
  37.     if (node.parentNode.parentNode.id == "menu") {
  38.         hideTopLevels();
  39.     }
  40.  
  41.     if (node.style.display == "") {
  42.  node.style.display = "none";
  43. } else {
  44.  node.style.display = "";
  45. }
  46.  
  47. }
  48.  
  49. function hideTopLevels() {
  50.     if (!document.getElementById) return false;
  51.     if (!(node = document.getElementById("menu"))) return false;    
  52.  
  53.     if (node.childNodes.length > 0) {
  54.         for (var i=0; i<node.childNodes.length; i++) {
  55.             var child = node.childNodes[i];
  56.             for(var j=0; j<child.childNodes.length; j++) {
  57.                 var grandchild = child.childNodes[j];
  58.                 if (grandchild.nodeName == "UL") {
  59.                     if (grandchild.style.display == '') {
  60.                         grandchild.style.display = "none";
  61.                     }
  62.                 }
  63.             }
  64.         }        
  65.     }
  66. }
  67.  
  68. function addLoadEvent(func) {
  69.     var oldonload = window.onload;
  70.     if (typeof window.onload != 'function') {
  71.         window.onload = func;
  72.     } else {
  73.         window.onload = function() {
  74.             oldonload();
  75.             func();
  76.         }
  77.     }
  78. }
  79.  
Thanks,
Ivan
Jan 24 '07 #1
3 5458
acoder
16,027 Recognized Expert Moderator MVP
You have not given the full code here. Where are prepare, collapse, etc. functions called? Have you seen the documentation for the free script? Which website did you get it from?
Jan 25 '07 #2
Irocivan
3 New Member
You have not given the full code here. Where are prepare, collapse, etc. functions called? Have you seen the documentation for the free script? Which website did you get it from?
Hello acoder,

There was missing only this part:
addLoadEvent(co llapseMenu);
addLoadEvent(pr epareMenu);

They are embedded with the previous code. The dynamic menu that I am using is based on the following link:

http://www.blazenewmed ia.com/articles/creating-a-dynamic-navigation-menu

From the example 2 in the page (http://www.cssdev.com/articles/menu/example2/) you can see a menu where the two parent codes are "Fruit" and "Vegetable" but none of the their respective links actually work but only the ones from the child nodes.

Greetings,
Ivan
Jan 25 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Having looked at the example and code, I now realise what your problem is.

I'm sorry but that is how it should work. When you click on a parent node, it opens a child menu. If the parent node just took you to another page, there would be no purpose in having a collapsing menu.
Jan 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4332
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i want to make first text as Table Heading/menu category. For examle in the given menu i want to make a heading as "Comp. Languages" which won't be a link. 2) The position of this menu is absolute to the page. I want to make it absolute to the Table...
2
5310
by: dannielum | last post by:
Hi all, I am trying to write a Binary Search Tree that each of its node will have 3 node pointers: left, right and parent. I need a parent pointer for some the purpose of my project. Without the pointer to the parent node, the program will be inefficient and slow. It works fine at first. However, when I started to build the remove function, it destroys the tree when I delete a node. I already changed the parent pointer whenever I delete a...
2
2684
by: Jenny | last post by:
My codebehind file contains a lot of sub's. Is there a fast way to expand and collapse them in the VisualStudio? It's really exhausting to collapse them all after opening the project in the morning! Thanks Jenny
14
11506
by: neerajb | last post by:
Hi, I am having an XML document(input.xml) which is showing the menu heirarchy used in my application.My requirement is to add "submenu" tag to those menuitems who are having the child menuitems as shown in output.xml. I am using VB.NET framework 1.1. Please Help, i have already invested my 2 days but unable to build the logic as input xml may be having any level of nesting of menuitems.
0
1425
by: sloan | last post by:
http://weblogs.asp.net/scottgu/archive/2006/01/17/435765.aspx http://aspnet.4guysfromrolla.com/articles/030806-1.aspx I've been looking for an implementation of a Menu Control that controls "drill down" on the non selected item. For Example, if my menu system looked like this -Home
5
15648
by: Homer J. Simpson | last post by:
Hi all, I just went over a *lot* of tree node style properties (LeftNodeStyle, NodeStyle, ParentNodeStyle, RootNodeStyle, LevelStyles, HoverNodeStyle, SelectedNodeStyle, etc etc etc) but can't find exactly what I want. It seems that I'm in a situation where none of these predefined groups fit the bill. Ultimately, the style to use needs to be decided as I'm dynamically adding individual nodes through code. I'd like to do this:
2
1402
by: xahlee | last post by:
In this week i wrote a emacs program and tutorial that does archiving a website for offline reading. (See http://xahlee.org/emacs/make_download_copy.html ) In the process, i ran into a problem with the unix “cp” utility. I've been a unix admin for Solaris during 1998-2004. Even the first time i learned about cp, i noticed some pecularity. But only today, i thought about it and wrote it out exactly what's going on. Here's a...
5
7520
by: Max2006 | last post by:
Hi, I have a TreeView and this is my node style: <asp:TreeNodeStyle ForeColor = "#000000" Font-Size="9px" Font-Bold="false" Width="100px" NodeSpacing="3px" /> The problem is the expand button (+) resides right at the middle of multi-line text. Can I make the expand button top align instead of middle align?
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.