Page 1 of 1

recursive menu building...

Posted: Fri Feb 11, 2005 3:04 pm
by mudkicker

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<style type="text/css">
.menutitle&#123;
cursor:pointer;
margin-bottom: 5px;
background-color:#ECECFF;
color:#000000;
width:140px;
padding:2px;
text-align:center;
font-weight:bold;
/*/*/border:1px solid #000000;/* */
&#125;

.submenu&#123;
margin-bottom: 0.5em;
&#125;
</style>

<script type="text/javascript">

/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

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

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

function SwitchMenu(obj)&#123;
	if(document.getElementById)&#123;
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block")&#123; //DynamicDrive.com change
			for (var i=0; i<ar.length; i++)&#123;
				if (ar&#1111;i].className=="submenu") //DynamicDrive.com change
				ar&#1111;i].style.display = "none";
			&#125;
			el.style.display = "block";
		&#125;else&#123;
			el.style.display = "none";
		&#125;
	&#125;
&#125;

function get_cookie(Name) &#123; 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) &#123;
offset = document.cookie.indexOf(search)
if (offset != -1) &#123; 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
&#125;
&#125;
return returnvalue;
&#125;

function onloadfunction()&#123;
if (persistmenu=="yes")&#123;
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
&#125;
&#125;

function savemenustate()&#123;
var inc=1, blockid=""
while (document.getElementById("sub"+inc))&#123;
if (document.getElementById("sub"+inc).style.display=="block")&#123;
blockid="sub"+inc
break
&#125;
inc++
&#125;
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
&#125;

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate

</script>
</head>

<body>
<!-- Keep all menus within masterdiv-->
<div id="masterdiv">

	<div class="menutitle" onclick="SwitchMenu('sub1')">Site Menu</div>
	<span class="submenu" id="sub1">
		- <a href="new.htm">What's New</a><br>
		- <a href="hot.htm">What's hot</a><br>
		- <a href="revised.htm">Revised Scripts</a><br>
		- <a href="morezone/">More Zone</a>
	</span>

	<div class="menutitle" onclick="SwitchMenu('sub2')">FAQ/Help</div>
	<span class="submenu" id="sub2">
		- <a href="notice.htm">Usage Terms</a><br>
		- <a href="faqs.htm">DHTML FAQs</a><br>
		- <a href="help.htm">Scripts FAQs</a>
	</span>

	<div class="menutitle" onclick="SwitchMenu('sub3')">Help Forum</div>
	<span class="submenu" id="sub3">
		- <a href="http://www.codingforums.com">Coding Forums</a><br>
	</span>
	
	<div class="menutitle" onclick="SwitchMenu('sub4')">Cool Links</div>
	<span class="submenu" id="sub4">
		- <a href="http://www.javascriptkit.com">JavaScript Kit</a><br>
			<span class="submenu" id="sub41">
				- <a href="http://www.javascriptkit.com">JavaScript Kit</a><br>
				- <a href="http://www.freewarejava.com">Freewarejava</a><br>
				- <a href="http://www.cooltext.com">Cool Text</a><br>
				- <a href="http://www.google.com">Google.com</a>
			</span>
		- <a href="http://www.freewarejava.com">Freewarejava</a><br>
		- <a href="http://www.cooltext.com">Cool Text</a><br>
		- <a href="http://www.google.com">Google.com</a>
	</span>

	<img src="about.gif" onclick="SwitchMenu('sub5')"><br>
	<span class="submenu" id="sub5">
		- <a href="http://www.dynamicdrive.com/link.htm">Link to DD</a><br>
		- <a href="http://www.dynamicdrive.com/recommendit/">Recommend Us</a><br>
		- <a href="http://www.dynamicdrive.com/contact.htm">Email Us</a><br>
	</span>

</div>
</body>
</html>
This is the JavaScript I want to use in my page but I have a problem. What I want to do is I have a categorized product tree which is included in this art of menu...

I was using before my client asked me to change it a css menu using <ul> and <li>'s.

Code: Select all

<?php
function menu_kur($id)
&#123;
global $l;
$mnq = @mysql_query("SELECT cat_id, cat_uid, cat_name FROM categories WHERE cat_hc = '".$id."' AND cat_delflag = '0' AND cat_lang = '".$l."' ORDER BY cat_uid ASC");
if (mysql_num_rows($mnq) > 0) &#123;
echo '<ul class="makeMenu">';
while ($row = mysql_fetch_assoc($mnq)) &#123;
echo '<li>';
menu_kur($row&#1111;'cat_uid']);
echo '<a href="products.php?l='.$l.'&id='.$row&#1111;'cat_id'].'">'.$row&#1111;'cat_name'].'</a></li>';
&#125;
echo '</ul>';
&#125;
&#125;
?>

Posted: Fri Feb 11, 2005 9:35 pm
by anjanesh
You may want to try out : http://gosu.pl/dhtml/mygosumenu.html

Posted: Sat Feb 12, 2005 10:23 am
by mudkicker
Thanks but i already tried hundreds of these scripts. It's not my idea to do it but my client...

Now I have to find out...