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.
JAVASCRIPT
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')
document.write('</style>\n')
}

function SwitchMenu(obj){
	
	if(document.getElementById){
	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";
		}else{
			el.style.display = "none";
		}

	}
	
}
PHP
Code:
function display_menu()
{
	
	connectsales();
	echo "<div id=masterdiv>";
	$query_menu="select * from menus";
	$result_menu=mysql_query($query_menu);
	$count=1;
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">";
	echo  "<tr>";
    
	while($row_menu=mysql_fetch_array($result_menu))
	{
		echo "<td width=\"110\" valign=\"top\" align=\"left\">";
		$id_menu=$row_menu['menu_id'];
		$query_menu2="select * from sub_menus where menu_id=$id_menu";
		$result_menu2=mysql_query($query_menu2);
		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>";
		while($row_menu2=mysql_fetch_array($result_menu2))
		{
			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>";
		$count++;
		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?