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
Cisco Lawsuit: A Test for the GPL?
Shifts for Enterprise Linux, Green Networks in '09
Gifts for All in Linux 2.6.28

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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Overview of Popular JavaScript Frameworks - ASP.NET AJAX · An Introduction to 3D · Email Marketing Terms to Know
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Samsung Introduces a 100GB Enterprise-Class SSD · Motorola Touch Tablet Aimed at Mobile Surfers · E-Commerce Tools: Five Ways to Sell Digital Goods Online

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

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