View Full Version : box open/close keeping state

07-21-2007, 06:59 AM

I am using that code

function shDiv(popup)

var box = document.getElementById(popup)
var a = document.getElementById(popup + '_a')
var t = document.getElementById(popup + '_t')

a.innerHTML =(a.innerHTML=='[ - ]')?'[ + ]':'[ - ]';
t.className =(t.className=='Tclose')?'Topen':'Tclose';
box.style.display = (box.style.display=='none')?'block':'none';

<a href="#" onclick="shDiv('box1');" id="box1_a">[ + ]</a>
<span id="box1_t" class="Topen">Box 1</span></h4>

<div class="shBox" id="box1" style="display:none;">Content 1</div>

it works fine but if a box is closed and the page is reloaded then the box open again, how is it possible to keep the box status : open if open , close if close ?

thank you

07-21-2007, 07:04 AM
You'd want to store a cookie and check that value when the page is loaded.