/    Sign up×
Community /Pin to ProfileBookmark

Hidden menu problem

Hi
ive got a problem. It’s one of those bugs you think are easy to solve, but after 5 hours of dealing with them make you sick.

I wanted a menu which will be hidden at the beginning, and appearing after clicking a button.
Ive got an easy script. firstly, the html table

[code=html] <tr>
<td title=”Show/Hide” onclick=”change(1)” style=”cursor: hand” onMouseOver=”style.backgroundColor=’#cecece’;” onMouseOut=”style.backgroundColor=’#F3F3F3′” class=”menuTable” width=”147″ height=”25″>&#187;
<a href=”#”>Products by Label</a><a onclick=”change(1)” href=”#”>

</a></td>
</tr>
<tr style=”display: none” id=”1″>
<td class=”menuTable” width=”147″ height=”25″ style=”background-color: #FFFFFF”>

</td>
</tr>

<!– Sub menu –>
<tr>
<td title=”Show/Hide” onclick=”change(2)” style=”cursor: hand” onMouseOver=”style.backgroundColor=’#cecece’;” onMouseOut=”style.backgroundColor=’#F3F3F3′” class=”menuTable” width=”147″ height=”25″>&#187;
<a href=”#”>Products by Category</a><a onclick=”change(2)” href=”#”>

</a></td>
</tr>
<tr style=”display: none” id=”2″ >
<td class=”menuTable” width=”147″ height=”25″ style=”background-color: #FFFFFF”>

<!— ASP lists the content of menu —>
[/code]

and the function:

[code=html]
<script type=”text/javascript”>
function change(id) {
ID = document.getElementById(id);

/* hiding the menu */
if (ID.style.display == “” ) {
ID.style.display = “none”;

}

else
/* showing the menu*/
{
ID.style.display = “”;

}
}
</script>
[/code]

ok, so the problem is – After each reload, it closes the menu. However, i want it to remain open until the user clicks the button again, or opens another category. does anybody have a smart idea to solve it?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsMay 15.2009 — [CODE]<!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" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
function change(id) {
ID = document.getElementById(id);

/* hiding the menu */
if (ID.style.display == "" ) {
ID.style.display = "none";



}

else
/* showing the menu*/
{
ID.style.display = "";

}
zxcCreateCookie(id,ID.style.display=='none'?1:2,1)
}

function zxcCreateCookie(nme,v,days){
document.cookie=nme+'='+v+';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path=/';
}

function zxcReadCookie(nme){
nme+='=';
var split = document.cookie.split(';');
for(var z0=0;z0<split.length;z0++){
var s=split[z0];
while (s.charAt(0)==' ') s=s.substring(1,s.length);
if (s.indexOf(nme)==0) return s.substring(nme.length,s.length);
}
return null;
}

function zxcRestore(){
for (var z0=1;z0<110;z0++){
if (document.getElementById('d'+z0)){
if (zxcReadCookie('d'+z0)&&zxcReadCookie('d'+z0)=='2'){
document.getElementById('d'+z0).style.display=''
}
}
else return false;
}

}
</script>

</head>

<body onload="zxcRestore();" >
<table>
<tr>
<td title="Show/Hide" onclick="change('d1')" style="cursor: hand" onMouseOver="style.backgroundColor='#cecece';" onMouseOut="style.backgroundColor='#F3F3F3'" class="menuTable" width="147" height="25">»
<a href="#">Products by Label</a><a onclick="change(1)" href="#">

</a></td>
</tr>
<tr style="display: none" id="d1">
<td class="menuTable" width="147" height="25" style="background-color: #FFFFFF">
Joe
</td>
</tr>

<!-- Sub menu -->
<tr>
<td title="Show/Hide" onclick="change('d2')" style="cursor: hand" onMouseOver="style.backgroundColor='#cecece';" onMouseOut="style.backgroundColor='#F3F3F3'" class="menuTable" width="147" height="25">»
<a href="#">Products by Category</a><a onclick="change(2)" href="#">

</a></td>
</tr>
<tr style="display: none" id="d2" >
<td class="menuTable" width="147" height="25" style="background-color: #FFFFFF">Tom
</td>
</tr>
</table>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@KlonauthorMay 16.2009 — That's fantastic, i cant thank you enough, u saved me loads of time ?

thanks again mate!
×

Success!

Help @Klon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...