Forum Moderators: coopster
I'm not sure if this is possible but I have a folding tree menu that was created in javascript. When you click a menu item at the highest level, the menu expands and the items at the next level are shown.
E.g
News
----
(When "News" clicked...)Today's News
(When "News" clicked...)Yesterday's News
(When "News" clicked...)News Archive
The problem I have is that when a link is clicked (E.g Yesterday's News) the folding tree menu is redisplayed and all menus collapse as the script does not hold details of what was clicked.
I'm trying to add PHP sessions to this script to resolve this.
<p class="nav_menu_head">
<a href="#" onclick="WM_toggle('toggle_0001'); return false<?php if ($nav_01 == 'CLOSE') {$_SESSION['nav_01'] = 'OPEN'; $nav_01 = 'OPEN';} else {$_SESSION['nav_01'] = 'CLOSE'; $nav_01 = 'CLOSE';}?>">Today's News</a>
</p>
In the above code, the php (to toggle between on and off) is always executed, even if the menu item is not clicked.
Can anyone tell me if it's possible to merge this code?
Cheers in advance all
In other words, the PHP code that you have in the onclick event is executed before the user even clicks on the menu, as it is run when loading the page. Which would explain why you're getting the problem of it always toggling.
It's difficult to offer much advice without seeing the javascript, but I presume there must be some sort of variable set in the javascript to determine whether a menu is expanded or not?
If so, the best way forward that I can see would involve using a variable in the URL. In other words, use this url for your links:
<a href="www.yoursite.com/latest_news.php?menuid=2">Latest News</a>
<a href="www.yoursite.com/todays_news.php?menuid=2">Todays News</a>
<a href="www.yoursite.com/yesterdays_news.php?menuid=2">Yesterdays News</a>
Then, when loading your page, you can use the php $_GET['menuid'] variable to make sure that the menu branch corresponding to 2 is expanded. In other words, do some sort of conditional statement on menuid and echo the correct variable (e.g. 'expanded', 'not_expanded') to the corresponding menu branch in the javascript.
Hope this all makes sense!
It would probably be easier to implement initially but much harder to change site-wide at a later stage.