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 ¬¬

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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;

}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.