Having lots of high quality content isn't enough. Visitors must know that the content is there to be had, and it must be easily accessible. In this article, I provide you with simple, straight forward code that creates an expanding menu.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Easy Expanding Menu Code

If you want your Web site visitors to stick around for a while, you need to provide lots of high quality content. But just having lots of high quality content isn't enough. Visitors must know that the content is there to be had, and it must be easily accessible.

The best solution is to place a complete menu on every page. But if you have a large quantity of content, your menu could get excessively long. One way to solve this problem is to provide an expanding menu. But most of the example code on the web for expanding menus is way too complicated to adapt for your own use.

In this article, I provide you with simple code that you can easily adapt to your own Web site. To keep it simple, the code will create a menu that expands only one level. Actually one level of expansion is all you should use, because going deeper causes loss of easy access to the content.

HTML Code for The Menu

The menu is constructed with an HTML table (<table> </table>). Each main menu and each submenu is coded as a row in the table (<tr> </tr>). Each submenu row contains two cells or table data elements (<td> </td>). Each main menu row contains one cell with its colspan attribute set to 2.

<tr>
  <td colspan="2"><a href="#" onClick="expandMenu(0); return false;">
  <img id="m0" border="0" src="closed.gif"">&:nbsp;Menu 0</a></td>
</tr>

Shown above is code for the first main menu item. Note that the table cell contains a link, and that the normal function of the link is disabled (by href="#" and return false;) and that instead the links onClick event is used to call a function named expandMenu, passing it the number of the menu (in this case 0, the first menu).

The link uses both an image (closed.gif) and text (Menu 0). Note the image has an id attribute which we can access with Java Script to change the image when the link is clicked. You change the text to the name of your menu item.

<tr id="sm00" style="display:none">
  <td>&:nbsp;</td>
  <td><a href="#">Submenu 0</a></td>
</tr>

Shown above is code for the first submenu item. Note that the table row has the style attribute set to display:none. This causes the table row to NOT be displayed. Note that the table row has an id attribute which we can access with Java Script to change the display style (to block to make it visible).

The first cell in the submenu row contains only a &:nbsp; (non-breaking space character code) which causes the submenu item to appear indented. The second cell in the submenu row contains a link. Replace the # in this link with the URL for your submenu item. The second cell in the submenu row also contains text (Submenu 0). You change the text to the name of your submenu item.

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Slide Show Code
Easy Slide Show Code with Mouseover Pause
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Java Script Timer Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Easy Expanding Menu Code
Web Designer's Reference
Object-Oriented JavaScript
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Code for Java Script Cube⁄Box Volume Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Disable IE8 Accelerators on Your Website
Prevent Automated Form Submissions With Java Script
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using the JavaScript Cookie Method
Password Protection Using the Frames Method
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Java Script Comparison Operators
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
Java Script Trim Function
Convert Mixed Number to Decimal
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV


[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2009 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269