tab menu
this is the javascript i have that displays a table when clicked on and hides it when clicked again:
function show(id){
el = document.getElementById(id);
if (el.style.display == 'none')
{
el.style.display='';
}else {
el.style.display='none';
}
}
i use the style="display: none" in the table. However i have more than one link, and when i click another that displays but under the first one. I cant figure out how to hide the first one then display the second one..?
I know it has something to do with remembering the current state, but how?
ACJavascripts posted this at 15:19 — 18th February 2007.
He has: 11 posts
Joined: Feb 2007
Hey,
well theres a couple ways you can do it...
1. You can create an array holding the IDs of your menus and have the "show" function close them all except for the selected ID.
2. You can send the "TOTAL" number of menus along with the ID and have the show function count out the other menus and close them all(or make sure they are all closed)
3. You can place all the menus into a "CONTAINER" and then run through the menus as if they where Nodes and check it they are open, if open close them.
Depending on how you can to go I can provide example code for any option, which do you think will work best for your menu system?
ACJavascripts.com - Free Cut and Paste Javascripts
SimplyProgram.com - Personal Blog
CYWebmaster.com - Webmaster Forum (re-designing)
benf posted this at 17:44 — 18th February 2007.
They have: 426 posts
Joined: Feb 2005
I like the sound of putting all the menu ids in to an array, seeing as when they are created they are from an array in the first place. Perhaps creating a new array from the current array, suppose it would make it an multi dimmensional array: $menu[itemID][ID] perhaps i could loop through picking out the array item that referes to the ID that has been clicked on?
Does this make sense.
Good Value Professional VPS Hosting
benf posted this at 13:58 — 20th February 2007.
They have: 426 posts
Joined: Feb 2005
Can someone help. It is really doing me in now. All i want to do is display the hidden table from the id that is passed in the function and hide all the other ids that have been displayed in the past.
module_variable='';
function module(get) {
if(document.getElementById) {
if (typeof(get) ==='string') {
get=document.getElementById(obj);
}
if(module_variable == get) alert(get);
}
function show(id) {
var get=document.getElementById(id);
if(get.style.display=='none'){
get.style.display='';
}
module(get);
}
here im trying to create a separate function that works out the last id so that i can close it before opening the next. Naturly it doesnt work. However at the moment im just trying to alert something.
Help im going mad!
Good Value Professional VPS Hosting
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.