SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remebering status of collapsed div

    Hey guys I have written a small function that will collapse the div I call it it from, however I also a some php that will be refreshing the page and/or going to the next page.

    Is there any way I can make the div remember that it is collapsed and wait for the user to un-collapse it? Here is my collapse code:

    HTML Code:
    function collapse(id, button) {
    
    		var buttonstatus = document.getElementById(button).getAttribute("src");
    		
    		if (buttonstatus == "images/collapse.jpg") {
    		
    			var button = document.getElementById(button).setAttribute("src", "images/expand.jpg");
    			
    		}else{
    		
    			var button = document.getElementById(button).setAttribute("src", "images/collapse.jpg");
    			
    		}
    		
    		var div = document.getElementById(id).style;
    		div.display = div.display ? "":"none";
    		
    	}
    My initial thought was to use a cookie and store the value of the collapsed state and do a check to see if its up or down. Is there a better way?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cookies are the only storage available to keep the information client-side.

    Other than that you could use AJAX to store the information server-side. But that's really an overkill, isn't it.
    Saul

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I've done something like that here with the box on the left. It's position is remembered by means of a cookie. The good thing is that this degrades nicely, if cookies aren't accepted then the last position simply isn't remembered and on reload it appears in the default position, which is hardly a catastrophe
    .

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Other than that you could use AJAX to store the information server-side. But that's really an overkill, isn't it.
    lol, maybe

    Looks like cookies will do then, now to learn how to use them in JS
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Other than that you could use AJAX to store the information server-side.
    Why would you do that when the page is getting reloaded anyway? In order to turn one request into two requests?

    When the div is collapsed you could write the div's id to a hidden form field along with it's state, e.g. "div1 collapsed". Your php could then read the form field and write the html so that the specified divs are collapsed.

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud View Post
    Why would you do that when the page is getting reloaded anyway? In order to turn one request into two requests?

    When the div is collapsed you could write the div's id to a hidden form field along with it's state, e.g. "div1 collapsed". Your php could then read the form field and write the html so that the specified divs are collapsed.
    Good point.
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •