SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Dynamic Menus
By Scott Isaacs

UPDATE - January 30, 2000
Adds linking capabilities to the root item (menubar items).

Our original menu toolkit makes it easy to create static drop-down menus. Juan Romero created a modified version of our script where the menus are defined in an Access database and generating when the page loads. This approach allows you to define, modify, and update your menus without ever having to touch the HTML page.

We are going to describe Juan's approach to managing and building the menus using Microsoft Access. The Microsoft Access Database has two tables - one containing the list of menu items, and a second table that defines the relationship between each menu item. This relationship defines the menu-hierarchy and (whether a menu-item contains a sub-menu with more choices).

The menu items table is named tblItems and has 12 fields:
IDAn auto-generated unique identifier for the menu item.
CaptionThe caption to display for the menu-item.
ToolTipA tooltip for the menu-item.
IconThe path to an icon for the menu item.
VisibleWhether or not to display the menu item.
EnabledWhether or not the menu option is currently enabled or disabled (grayed out).
EffectDateDate the menu option is to be made available.
EndDateDate the menu option is to no longer be available.
EnteredDateThe date and time the menu option was added.
EnteredByThe name of the user who added the option.
URLA URL to navigate to when the menu option is selected.
OwnerThe owner of the content represented by the menu option.

Below we create two sample entries:
FieldMenu Items
ID5758
CaptionLinksSiteExperts
TooltipUseful LinksSite Experts is a wonderful site for web developers (DHTML,XML,ASP,etc.)
Icon htmlicon.gif
VisibleTrueTrue
EnabledTrueTrue
EffectDate1/19/00 12:42:41 PM1/19/00 12:42:41 PM
EndDate  
EnteredDate1/19/00 12:42:51 PM1/19/00 12:42:51 PM
EnteredBy  
URL http://www.siteexperts.com
Owner  

This creates two separate menu entries, Links and SiteExperts.com. The next step is to specify that the SiteExperts.com option is a sub-menu of the Links menu choice. This relationship is defined in separate table named tblParents:
IDThe ID of a menu option.
ParentThe ID of the parent menu choice.

To make the SiteExperts.com menu option a child of the Links menu option you need to add a row to this table. The ID field needs to represent the ID of the child (SiteExperts.com) and the parent field needs to represent the parent menu option (Links).
IDParent
5857

To create a top-level menu-item do not make the menu-item a child of any other item. Therefore, the Links menu option is not a child of any other menu-item. This table also supports nested menu items. For example, you can add your favorite SiteExperts.com links as children of the SiteExperts.com menu choice by adding them to to the items table and making SiteExperts.com's ID (58) the parent of those choices.

By combining this access database with the modified script, your menus are all set to go. On the next page, you can download and view the complete script.

Page 1:Dynamic Menus
Page 2:The Script