| px | top | add code | search | signup | login | help |
Requires the "hierMenus.js" file, found at: www.dhtmlab.com.
<!-- Copyright (c) 1999 by Zebadiah Kimmel, zkimmel@earthlink.net.--!>
<!-- All Rights Reserved. --!>
<!-- Feel free to reuse this code as long as you give me credit --!>
<!-- at the web page where you reuse it. --!>
<!-- (Note that the hierMenus code also requires credit--see "hierMenus.js" for details.) --!>
<!-- load the hierMenus.js source file !-->
<script src="hierMenus.js"></script>
<?php
// creates the javascript code for a hierarchical menu
// requires a menu identifier and three arrays (all the same size) as input
// warning: if a name or an href contains a single quote ', things will go wrong
// identifier 1 means menu number 1, 2 means menu number 2, etc (in which case title is used)
// identifier 1_1 means submenu 1 of menu 1
// identifier 1_2 means submenu 2 of menu 1
// identifier 3_4_1 means submenu 1 of submenu 4 of submenu 3
// and so on
function buildMenu($identifier, $name, $href, $submenu, $title="")
{
echo "<script> ";
echo "\n";
$num=count($name);
if (strchr($identifier,"_"))
echo "arMenu" . $identifier . " = new Array(";
else
{
// modify the hex (#RRGGBB) numbers to get different colors
echo "arMenu" . $identifier . " = new Array(null, 0, 0, '#000000','#000000', '#00FFFF','#FFFF00', '#008888','#008888'";
if ($num>0)
echo ",";
else
echo ",'None','javascript:hideAll();',0";
}
for($i=0; $i<$num; $i++)
{
$n=$name[$i];
$h=$href[$i];
$s=$submenu[$i];
echo "'$n','$h',$s";
if ($i<$num-1)
echo ",";
}
echo "); ";
echo "\n";
echo "</script> ";
echo "\n";
if (!(strchr($identifier,"_")))
{
echo "<A CLASS=leftMenuMore HREF='javascript:void(0)' ";
echo "onMouseOver='popUp(\"elMenu".$identifier."\",event)' onMouseOut='popDown(\"elMenu".$identifier."\")'> ";
echo "$title";
echo "<IMG SRC='triangle.gif' WIDTH=10 HEIGHT=10 BORDER=0 ALT=''></A>";
}
}
// Modify the following for your own application.
$name=array("CNN","Tribune","NY Times");
$href=array("http://cnn.com", "javascript:alert(\'hello\')", "http://nytimes.com");
$submenu=array(1,0,1);
buildMenu("1",$name,$href,$submenu, "Click on me");
$name=array("Washington Post","Mercury Star","Wall St Journal");
$href=array("http://washingtonpost.com", "javascript:alert(\'aloha\')", "http://wsj.com");
$submenu=array(0,0,1);
buildMenu("1_1",$name,$href,$submenu);
$name=array("Star Wars");
$href=array("http://starwars.com");
$submenu=array(0,0,0);
buildMenu("1_1_3",$name,$href,$submenu);
$name=array("Apple","IBM","Dell");
$href=array("http://apple.com", "http://ibm.com", "http://dell.com");
$submenu=array(0,0,0);
buildMenu("1_3",$name,$href,$submenu);
echo "<P>";
$name=array("Mattel", "Hasbro");
$href=array("http://mattel.com", "http://hasbro.com");
$submenu=array(0,1);
buildMenu("2",$name,$href,$submenu, "Click on me also");
$name=array("Lego");
$href=array("http://lego.com");
$submenu=array(0);
buildMenu("2_2",$name,$href,$submenu);
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.