Hi everyone!
I’m new to javascript and I run into a problem here. I’m currently building a clam shell menu, one that shows/hides its sub-menu when it’s clicked. I’d like to maintain the state of this menu across different pages without using cookies. I’m not sure if there’s such a thing as global static variable in javascript but I tried. The code is shown as below:
[COLOR=red]
var sub_1 = 0;
var sub_2 = 0;
function toggleClamShellMenu(objectID) {
var object = document.getElementById( objectID );
if( object.style.display == ‘block’ ){
object.style.display = ‘none’;
if( objectID == ‘menu1’ ) sub_1 = 0;
if( objectID == ‘menu2’ ) sub_2 = 0;
}
else{
object.style.display = ‘block’;
if( objectID == ‘menu1’ ) sub_1 = 1;
if( objectID == ‘menu2’ ) sub_2 = 1;
}
return;
}
function initialShellMenu(){
var object = document.getElementById( ‘menu1’ );
if( sub_1 == 1 ) object.style.display = ‘block’;
object = document.getElementById( ‘menu2’ );
if( sub_2 == 1 ) object.style.display = ‘block’;
}
[/COLOR]
The body tag calls the [COLOR=red]initialShellMenu()
Respect to all of you! Tks!