PDA

View Full Version : Help Scripting


guertzen
09-03-2002, 02:01 AM
I have this script to make a table menu:

function change() {
if(!document.all)
return
if (event.srcElement.className=="expandable"){
var x=event.srcElement.parentElement
if (x.all[2].style.display=="none"){
x.all[2].style.display='';
}
else {
x.all[2].style.display="none"
}
}
}
document.onclick=change

The problem is that when I click on any menu object he keeps expanded and dont contract automatic when I click on another one object menu. Only contract if I click in the same object menu. How can I contract automatic? Thanks and sorry my bad english.

mordred
09-03-2002, 09:12 PM
You have to store a reference to the previous expanded menu somewhere in a variable. Then, upon clicking on a different menu, you contract the menu pointed to by the stored reference and store the current menu anew in this variable (if possible, i.e. if it's "expandable").

Quick hack, not tested, but should give you an idea how it could work:


var lastMenu = null;

function change() {
if(!document.all) {
return;
}
if (event.srcElement.className=="expandable"){
if (lastMenu != null) {
lastMenu.all[2].style.display="none";
}

var x=event.srcElement.parentElement;

if (x.all[2].style.display=="none"){
x.all[2].style.display = '';
lastMenu = x;
}
else {
x.all[2].style.display="none";
}
}
}