C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

creating menu item


Posted Date: 10 Aug 2008      Posted By: Lanka Harini      Member Level: Silver     Points: 1   Responses: 1



hii, I am trying to create a switch menu but I am not getting it correct..( Like I have Categories like Languages and operating systems.When I click on Language the subcategories under it ie(dotnet,Java and C )should open.similarly Under OS windows,linux and unix..When I click on dotnet the categories like asp.net,C#,vb.net should be opened..similarly for rest of the things.Main thing is only one category should open at a time remaining all categories must close..


This is the code which I have written pls go through it n send me the correct code.

under Javascript I have written the following code:
====================================================
<head runat="server">

<script type="text/javascript">



var persistmenu="yes"

var persisttype="sitewide"



if (document.getElementById){

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");

if(el.style.display != "block"){

for (var i=0; i<ar.length; i++){

if (ar[i].className=="submenu")

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
















var persistxyx="yes"

var persisttype="sitewide"



if (document.getElementById){

document.write('<style type="text/css">\n')

document.write('.cat{display: none;}\n')

document.write('</style>\n')

}



function SwitchCat(obj){

if(document.getElementById){

var el = document.getElementById(obj);

var ar = document.getElementById("masterdiv").getElementsByTagName("span");

if(el.style.display != "block"){

for (var i=0; i<ar.length; i++){

if (ar[i].className=="cat")

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 (persistxyz=="yes"){

var cookiename=(persisttype=="sitewide")? "switchCat" : window.location.pathname

var cookievalue=get_cookie(cookiename)

if (cookievalue!="")

document.getElementById(cookievalue).style.display="block"

}

}



function savexyzstate(){

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")? "SwitchCat" : 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 (persistxyz=="yes" && document.getElementById)

window.onunload=savexyzstate



</script>


</script>
</head>

code:
==================================================================

<body ms_positioning="GridLayout">
<form id="form1" method="post" runat="server">
<div id="masterdiv">
<div class="menutitle" onclick="SwitchMenu('sub1')">
Languages</div>
<span class="submenu" id="Sub1">
DotNet<br />
Java<br />
C
</span>

<div class="xyz" onclick="SwitchCat('asz1')">
DotNet</div>
<span class="cat" id="asz1">Asp.net<br />
C#.net<br />
VB.net </span>
<br />


<div class="xyz" onclick="SwitchCat('asz2')">
Java</div>
<span class="cat" id="asz2">Struts<br />
core<br />
advance </span>
<br />


<div class="menutitle" onclick="SwitchMenu('sub2')">
Operating Systems</div>
<span class="submenu" id="sub2">Windows<br />
Linux<br />
Unix </span>
</div>
</form>
</body>






Responses

Author: Rathi    12 Aug 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

hai

try this javascript

http://www.dynamicdrive.com/dynamicindex1/switchmenu.htm

http://www.dynamicdrive.com/dynamicindex1/switchmenu2.htm



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Difference between dispose and gc.collect
Previous : multi-tier
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use