/    Sign up×
Community /Pin to ProfileBookmark

Folding menu – remembering current selection – howto?

Hi all ?

I have a bit of a problem with remembering current pathway (selection in menu) and I need your help. I am new to JavaScript.

But let’s get back to where it’s started. I am currently developing a simple CMS in PHP & MySQL. Most of work is already finished, bu now I have to tweak some functionalities in increase user experience ?

One of it is folding menu (tree menu). I am generating it in PHP and currently I’m using simple JavaScript to expand/collapse submenus (folders). Idea is simple – when an expandable list item (<li>) is clicked (onmouseclick) a simple JS funtion is executed that display a child list (<ul>) and in this way I am building a simple tree menu. The function is following:

[CODE]function showHide(msg_id)
{
var element = document.getElementById(msg_id);
element.style.display = element.style.display==’block’ ? ‘none’ : ‘block’;
}[/CODE]

The problem is that when I click an list item (that leads to certain article) in a submenu, whole page is reloaded and all previously opened submenus collapse. I would like to have expanded elements that are leading to the last one that I clicked.

How can I achieve it? Can you provide me some links to tutorials? Or maybe giva a hint how to tweak my function?

I was trying to google some help but I probably use wrong keywords…

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERAug 24.2010 — Try using a cookie to save the current menu location and status (block|none).

Then when the page is reloaded, retrieve the last saved menu location and status from the cookie.

There are lots of "javascript cookies" you can google about.
×

Success!

Help @fakirinho 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...