spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column15

Logo

Cross-Browser Hierarchical Menus
second and third level menu creation

Webreference

Contents

Open the menus above to remind yourself that this is a technique worth learning.

In longer script listings, cross-browser code is blue, Navigator-specific code is red, and Explorer code is green.

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The functions that create the second and third level menus are completely cross-browser, as they use custom functions and methods defined elsewhere.

We repeat them here for the sake of completeness. For a detailed discussion on the statements, refer to our previous column.

Second Level Menu Creation

function makeSecond() {
   secondCount = topCount + "_" + topItemCount;
   
   secondArray = eval("arMenu" + secondCount);
   secondName = "elChild" + secondCount
   
   secondMenu = makeElement(secondName);
   secondMenu.setup = menuSetup;

   secondItemCount = 0;
   for (j=0; j<secondArray.length; j+=3) {
      secondItemCount++;
      secondItemName =  (keep with next line)
        "item" + secondCount + "_" + secondItemCount;

      secondItem = makeElement(secondItemName,secondMenu)      
      
      if (secondItemCount > 1)
         secondItem.prevItem = (keep with next line)
eval("item" + secondCount  + "_" +(secondItemCount-1));

      secondItem.setup = itemSetup;
      secondItem.setup(j,secondArray);
      
      if (secondItem.hasMore) makeThird();
   }

   secondMenu.setup(true,secondItem,topMenu,topItem);
}

Third Level Menu Creation

function makeThird(){
   thirdCounter = secondCount + "_" + secondItemCount;
   
   thirdArray = eval("arMenu" + thirdCounter);
   thirdName = "elGrandChild" + thirdCounter;
   thirdMenu = makeElement(thirdName)
   
   thirdMenu.setup = menuSetup;

   thirdItemCount=0;
   for (k=0; k<thirdArray.length; k+=3) {
      thirdItemCount++;
      thirdItemName =  (keep with next line)
         "item" + thirdCounter + "_" + thirdItemCount;
      thirdItem = makeElement(thirdItemName,thirdMenu);

      if (thirdItemCount > 1)
         thirdItem.prevItem =  (keep with next line)
eval("item" + thirdCounter + "_" + (thirdItemCount-1));

      thirdItem.setup = itemSetup;
      thirdItem.setup(k,thirdArray);

   }

   thirdMenu.setup(true,thirdItem,secondMenu,secondItem);
}

Now, that was an easy page. With all our menus created, we wait for the user to mouseover one of the links associated with a menu.


Produced by Peter Belesis and

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

All Rights Reserved. Legal Notices.
Created: Feb. 27, 1998
Revised: Feb. 27, 1998

URL: http://www.webreference.com/dhtml/column15/menu2Child.html