Show/hide DIV problem with reload

Hi friends,

I have a problem that needs your help :slight_smile:

If you see this site: http://www.nosotroscinco.com

you will see the button +info

By clicking there, I show or hide a <div> using the below js function:


<script language=“javascript”>
function toggle() {
var ele = document.getElementById(“toggleText”);
if(ele.style.display == “block”) {
ele.style.display = “none”;
}
else {
ele.style.display = “block”;
window.scrollTo(100,300)
}
}
</script>


The problem I have here, is that each time the “next” or “prev” buttons are pressed (< or >) reload the page, and I want to reload the URL but with last status for the ele.style.display.

I don´t know if I am clear enough, but for instance, I open the website home, then click in +info, it shows the hidden div, then click in next button “>”, I want that +info is opened if previously it was opened.

I really appreciate your help on this, I am driving crazy and cant solve this.

Thanks & Best regards

Thinking a bit more about it, yes GET would be easier.

Just append the current status (dispStatus) in a query string to the url that your < and > point to and then use code along the lines of -

 
<script type="text/javascript">
 
var dispStatus = <?php  echo $_GET['txtDispStatus']; ?>;  
 
function toggle() {
     dispStatus = (dispStatus == 'block')? 'none' : 'block';
     elem.style.display = dispStatus;
}
 
window.onload=function() {
    elem = document.getElementById("toggleText");
    elem.style.display = dispStatus;
}
 
</script>

Thank you Kalon, I am already using php, but I am using GET, not post. If you click in < or >, you will see it in action.

I don´t see how I can implement what you have sent to me, thankyou any way !

If you can use php, you can store the display status of the div (dispStatus) in a session variable. Each time the +info is clicked you also update a hidden input element with the current display status.

On each page load you check the value of the hidden element being passed to the page and then store it in a global javascript variable.

 
<script type="text/javascript?>
 
var dispStatus = <?php  echo $_POST['txtDispStatus']; ?>;
 
</script>

If you have to do it on client side only, you can either use cookies to store the current display status or append the display status as a query string parameter the the page’s url and then parse the quesry string on each page load to get the current display status.

I’m not sure what you mean in the red text :frowning:

Thanks Kalon, that would work fine, but not completely, since I have too an swf movie that links to other pages, and too need to pass the status that holds the javascript function, in this case I think it´s impossible… not sure.

no.

hahaha Kalon, the status for the div to be hidden/shown, is changed by the javascript function toggle(), and this status should be passed to the swf movie too, in order to click in next/prev buttons that this swf movie holds.

Clear ? mmmm I don´t think !!! my english suck

I am guessing if you want to do something with your SWF, you would need to use ActionScript within your SWF to grab/know where it is (next/prev)