View Full Version : [HELP] Javascript change style.display problem with unnecessary multiple clicks.

04-19-2005, 09:01 PM
Hey Everyone. I'm new here and I'm far from great with Javascript. Anyway, after many uneventful hours of trying to find a pre-built tree navigation system that was as simple as what I wanted I decided that (like always) it'd probably be best to spend the time and whip something up myself. So I scavenged around and put this together. http://extstudios.com/new/ (see the left bar). Now, It works great but it has a 1 minor problem.

If you click back and forth between Section 1 and Section 2 sometimes you have to click two times to make the which ever section expand/contract. Its easier if you just try it. Go to the link above and start clicking back and forth between section 1 and section 2. You'll see what I mean. So the question is, how to get rid of this extra click non-sense. Thanks everyone!


Harry Armadillo
04-19-2005, 09:41 PM
You're using a single variable state to save/set the display state of your divs. Two divs one state variable...what happens when the state variable matches the state of last menu change, but not the state of the currently clicked menu?

Either: use an array of state variables; or (better) don't try to store the state--have your onclick function check fetch the current contents of the display property and act accordingly.

BTW, eval( "document.all." + layer_ref + ".style.display = state"); is horrible ugly and slow. Try document.all[layer_ref].style.display = state;

04-19-2005, 09:55 PM
Thanks Harry! Workin on it now.

04-19-2005, 10:04 PM
And its fixed! Thanks again Harry!