...

View Full Version : anyone have some input on expanding a Javascript menu?



cimmerin
01-24-2006, 01:30 AM
Hi,

I am still trying to figure out if it's possible to take this menu and customize it so that when a page on the menu is clicked it carries the expand to the next page. This will help users know where they are at. (not breadcrumbs) I have included the head tag script and the body script. example..

Lets say that this is the menu and I just clicked on Autos...

it expands, then I click on Ford and now I'm at the Ford page..

the menu as it stands closes back to the original state non expanded.

Autos
Ford
Chevy
Mercury
Dodge

The <head tag>

<script type="text/javascript">

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){ //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";
}
}
}

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

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

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

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>


the <body>

<!-- Keep all menus within masterdiv-->

<div id="masterdiv">
<div class="menutitle" onclick="SwitchMenu('sub1')"><a href="/orderform.htm"><font color="#FFFFFF">Order
Form</font></a></div>
<div class="menutitle" onclick="SwitchMenu('sub2')">Our
Product Lines</div>
<span class="submenu" id="sub2"> - <a href="/egyptiangoddess.htm">Egyptian
Goddess</a><br>
- <a href="/perfumeoils.htm">Perfume Oils</a><br>
- <a href="/incense.htm">Incense</a><br>
- <a href="/perfumesolids.htm">Perfume Solids</a><br>
- <a href="/packagedincense.htm">Packaged Incense</a><br>
- <a href="/temporarytattoos.htm">Temporary Tattoos</a><br>
- <a href="/accessories.htm">Accessories</a><br>
- <a href="/topsellerslist.htm">Top Sellers List</a> </span>
<div class="menutitle" onclick="SwitchMenu('sub3')">About
Auric Blends</div>
<span class="submenu" id="sub3"> <a href="/auricblendshistory.htm">-
History</a><br>
- <a href="/businesspractices.htm">Our Business Practices</a><br>
</span>
<div class="menutitle" onclick="SwitchMenu('sub5')"><a href="/prayforpeace.htm"><font color="#FFFFFF">Pray
for Peace</font></a></div>
<div class="menutitle" onclick="SwitchMenu('sub6')"><a href="/sellingtips.htm"><font color="#FFFFFF">Selling
Tips</font> </a></div>
<div class="menutitle" onclick="SwitchMenu('sub7')">About
Fragrance Products</div>
<span class="submenu" id="sub7"> - <a href="/fragrancehistory.htm">Fragrance History</a><br>
- <a href="/fragranceterminology.htm">Terminology</a></span>
<div class="menutitle" onclick="SwitchMenu('sub8')">Fragrance
Info</div>
<span class="submenu" id="sub8"> -<a href="/fragranceindustryresources.htm">
Industry Resources</a><br>
- <a href="/fragranceindustrynews.htm">Fragrance News</a><br>
</span>
<div class="menutitle" onclick="SwitchMenu('sub9')"><a href="/newsletter.htm"><font color="#FFFFFF">Wholesale Newsletter</font></a></div>
</div>
<div class="menutitle" onclick="SwitchMenu('sub10')"><a href="/monthlyarticle.htm"><font color="#FFFFFF">Monthly
Article</font></a></div>

Can anyone help?

cyber11
01-24-2006, 03:21 AM
How about one that already has cars in the menu?
http://www.yxscripts.com/cs/examples/demo10.html

-Bill



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum