View Full Version : need a menu

08-01-2006, 05:26 PM
Hi all,
I have this script drop menu that i got from dynamic drive. It use javascript and php to extract the menus. The problem is that its not a 100% what i need i modified and modified but i've reached this stage where i don't know what to do anymore and since am not that good in javascript, m seeking for some help. first here is the code.

* Visit http://www.dynamicdrive.com/ for full source code

var persistmenu="no" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="local" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')

function SwitchMenu(obj){

var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
if(el.style.display != "block"){ //DynamicDrive.com change
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu") //DynamicDrive.com change
ar[i].style.display = "none";
el.style.display = "block";
el.style.display = "none";




function display_menu()

echo "<div id=masterdiv>";
$query_menu="select * from menus";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">";
echo "<tr>";

echo "<td width=\"110\" valign=\"top\" align=\"left\">";
$query_menu2="select * from sub_menus where menu_id=$id_menu";
echo "<div class=menutitle_w>";
echo "<div class=menutitle onclick=SwitchMenu('sub".$count."') onmouseout=SwitchMenu('sub')>&nbsp;".$row_menu['menu']."</div>";
echo "<span class=submenu id=sub".$count.">";
//echo "<ul>";
echo "<a href=".$row_menu2['link']."?id=".$row_menu2['sub_menu_id'].">".$row_menu2['sub_menu']."</a><br>";
//echo "<li><a href=http://localhost/nabridas/files/product_display.php?id=".$row_menu2['subcat_id'].">".$row_menu2['subcat_name']."</a></li>";

//echo "</ul>";
echo "</span>";
echo "</div>";
echo "</td>";
echo "</tr></table>";
echo "</div>";


Now what happens it that when the user clicks on the menu a list of submenu appears all being generated from a table that i've created and some php codes. The user click on the submenu and this goes to the link that i've specified. So far everything is fine, but the problem is when the user clicks but doesn't select any submenu, and clicks somewhere else on the screen, i would need something another function that collapse the whole thing, tried different ways for e.g. i've put a mouseout event but the whole find collapses even when the mouse is over the submenu. Can anybody help me to do this please?