Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2006, 10:18 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Array driven menu

Greetings~

I have built an array driven menu system. I just wanted to show how I did it and get any feedback on better practices...more elegant code. Lemme know your thoughts. Here is the code...

Normal array...yada...yada...yada

    var MyTrainingMenuItems = new Array();
    MyTrainingMenuItems[0] = new Array();

    MyTrainingMenuItems[0][0] = "Current";
    MyTrainingMenuItems[0][1] = "somewhere.htm";
    MyTrainingMenuItems[0][2] = "Current Registrations";

<div id="menu">
        [list]<li><a href="#"onclick="javascript:showmenu('smenu1');">M y Training</a></li></ul>
            <div id="smenu1">
                    <script language="javascript">
                        var loopCounter;
                        for (loopCounter = 0; loopCounter < MyTrainingMenuItems.length; loopCounter++)
                        {
                            document.write("<li><a href='" + MyTrainingMenuItems[loopCounter][1] + "'>" + MyTrainingMenuItems[loopCounter][2] + "</a></li>");
                        }
                    </script>
            </div>
        [list]<li><a href="#" onclick="javascript:showmenu('smenu2');">Applicati on Training</a></li></ul>
            <div id="smenu2">
                    <script language="javascript">
                        var loopCounter;
                        for (loopCounter = 0; loopCounter < ApplicationTrainingItems.length; loopCounter++)
                        {
                            document.write("<li><a href='" + ApplicationTrainingItems[loopCounter][1] + "'>" + ApplicationTrainingItems[loopCounter][2] + "</a></li>");
                        }
                    </script>
            </div>
        [list]<li><a href="#" onclick="javascript:showmenu('smenu3');">Recommend ed Path</a></li></ul>
            <div id="smenu3">
                    <script language="javascript">
                        var loopCounter;
                        for (loopCounter = 0; loopCounter < RecommendedTrainingPathsItems.length; loopCounter++)
                        {
                            document.write("<li><a href='" + RecommendedTrainingPathsItems[loopCounter][1] + "'>" + RecommendedTrainingPathsItems[loopCounter][2] + "</a></li>");
                        }
                    </script>

The above is the actual menu and this is the showmenu function..

window.onload=showmenu;
function showmenu(id) {
var d = document.getElementById(id);
    for (var i = 1; i<=10; i++) {
        if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display= 'none';}
    }
if (d) {d.style.display='block';}
}

Let me know if you guys have any better ideas. I played around with css driven menus and differing types of js menus.


Clay Hess
__________________
Clay Hess





Similar Threads
Thread Thread Starter Forum Replies Last Post
Database driven drop down rajneesh Classic ASP Professional 3 May 5th, 2007 01:39 AM
Data Driven Query Task forkhead SQL Server DTS 1 June 22nd, 2006 11:01 AM
Data-Driven Subscription Markus27 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 May 12th, 2006 08:42 PM
Creating a Database Driven Top Menu Bar with CSS Lucy CSS Cascading Style Sheets 1 March 30th, 2006 10:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.