Jump to content

Maintaining property values after page refresh?


coldkill

Recommended Posts

Hey folks,

at the moment I've created a script that hides/shows a navigation bar and side bar on my site. I'm now looking for a way of keeping these hidden when the user hides them after the page has been refreshed.

 

Any ideas? I did try a search but didn't really know what to search for ¬¬

I think the best way would be to use a session variable in php to determine whether or not to start the bar open or closed. It could be as simple as the php setting a variable for your javascript:

<script language="Javascript">
   var navbar = <?php echo $_SESSION['navbar'] ?>;
</script>

But then how would I modify the session?

 

Here's the code I've got at the moment which does two things: First it adjusts the display property of the specified element, secondly, it adjusts the width of the central content area.

 

If I used your above sample, would I not need to reload the page and use php to adjust the session?

 

Thanks for the help,

Mike

 

::EDIT::

Helps if I attach the code ¬¬

 

This is in a separate .js file.

// Content area width
var contentWidth = 660;

// Toggle the navigation bar
function toggleDisplay( id )
{
var element = document.getElementById( id );
var content = document.getElementById( "content" );

if( element.style.display == "none" )
{
	element.style.display = "";

	// Adjust the content area variable
	contentWidth = contentWidth - 120;

	// Adjust content area width
	content.style.width = contentWidth;
}
else
{
	element.style.display = "none";

	// Adjust the content area variable
	contentWidth = contentWidth + 120;

	// Adjust content area width
	content.style.width = contentWidth;

}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.