I am looking for some help with my menu setup. On the left side of the page, I have the main menu. Each item on that menu has a submenu, displayed on the right. Rather than setting up a page for each item on the main menu, on which I include the appropriate submenu, I would like to try to use a javascript to unhide (the CSS for each submenu starts out with display:none) the appropriate submenu when the associated item on the main menu is clicked, without moving to another page.
The main menu would essentially be redone as a dummy menu, acting and looking like a link but not leading anywhere. I was also hoping to be able to have the currently 'active' item (that is, the item that has its submenu showing) use the 'on' graphic and a different pointer than the regular one for links. Similarily, when someone selects one of the items on one of the submenues, I'd like that item to act the same way.
Here's something to play with
you can see it working here (not linked because I don't want spiders in my test site)
www.cands.dnsalias.com/articles/css/menus/collapsing-javascript/
it will go on the main site when written up
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares? Code Samples | People Counting System
I think I sort of see how that is supposed to work. Although, I made a quick attempt at integrating it with my existing page, and I can't quite seem to get it right.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares? Code Samples | People Counting System
At the moment, the unhiding doesn't seem to work at all. I've probably made a mistake with the naming, as I needed to keep my old naming scheme to keep my other script working, but I can't see what I'm missing.
naming will most likely be the problem. It should be possible to wrap your existing <div>s in containers named and referenced for this script though.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares? Code Samples | People Counting System
That's probably true, although if possible I'd like to avoid adding more divs.
I imagine its the 'i' variable in the script that is causing the problem, since I am not using numbered submenus (I find it makes it more awkward to keep track of them that way) ... but perhaps it could be altered to work with a different naming scheme?
What, for example, does this bit do:
Code:
for (i=0; i<=Menu.length-1; i++) {
document.getElementById('Menu'+Menu[i]).style.display = 'none';
}
Now you see I'm glad you asked that, because it will be the small but relatively important bit of code that some halfwit missed including in the original post.
Code:
var Menu = new Array("one","two","three");
change the array names to match your containers
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares? Code Samples | People Counting System
Last edited by chrishirst : 04-21-2005 at 02:29 PM.
Now, I just need to fiddle with the positioning of the submenus, and see if I can tweak the script (or use another script) to allow me to indicate which item's submenu is currently being displayed, and which section of a submenu has been selected.
I just tested the page in Opera 8, and there the script for hiding and unhiding the submenus breaks down. Instead of hiding the previous submenu when you click to load another, Opera just layers them on top of each other.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares? Code Samples | People Counting System
no idea, I've got Opera 7 installed and a bit loath to change after the standards disaster that was ver 6 at least 7 works (sort of)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares? Code Samples | People Counting System
After much fiddling and many questions I finally managed to get this hide/unhide script to work together with PHP to yield the right result on interior pages ... only to find that it no longer works on the main page.
On the main page, clicking on any of the menu items on the left side should bring up a submenu on the right side. It should also mark the clicked item on the left menu as 'selected' by switching to the mouseover graphic (darker & underlined) and to a regular arrow-cursor.
Essentially, it should work just as the interior page, with the exception that it shouldn't start with a submenu loaded and an item on the main menu and the submenu selected (as these are indicators of which interior section the visitor has reached).