Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Maintaining state

Posted on 2003-12-11
Medium Priority
Last Modified: 2006-11-17
Hi, I have PHP and javascript. I have a nice DHTML page I made for a menu thingy, that has a number of links that can be shown/hidden.  When the user returns to the page it is reloaded from the server and rebuilt.  But I would like the users to be able to return to it in the state they left it.  The thingy has lots of hide/show sections. I guess I could get javascript to send a record of all the show states to the server as GET parameters, or maybe even POST an array of thingy states along when a link is selected - so the server could recreate it in the same state.  But what I was wondering is whether I can get javascript to keep and update the show states client-side between pages, somehow, and reload them?  Would a cookie allow this?
Question by:kaller2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 22

Accepted Solution

pjedmond earned 252 total points
ID: 9923847
Yes - cookies are probably the way to go, BUT, some people disable cookies, so this process cannot be reliedon:(

He is a link on how to to set/reset/read cookies:


LVL 25

Assisted Solution

by:James Rodgers
James Rodgers earned 248 total points
ID: 9923927
LVL 16

Expert Comment

ID: 9925665
If your using php, then i would forget the cookies all together
and set a var on the server some how when a menu is expanded and when it is closed.

just use either hidden form fields, and onload have an init function to read the hidden field value(s) and then show or hide the menu(s)  


You could pass a query string thru the link and use php to read the query str and set your menu up like that, or use location.search in javascript to read it.

Author Comment

ID: 9928185
Yes I have heard these urban myths that some people turn off cookies, but I have yet to meet one of these mythical beings that programming folk legends thrive apon.  I imagine they eat their meat raw and light fire by rubbing sticks together.  Tales of latterday luddites?  Lump these with the half a dozen users world wide using Netscape 3 no doubt?  And thin client ?  It is not always a good idea to hammer the pipe to the server when you have a gazillion megaflops lying idle on the users desktop?  Idle that is apart from the mis-application of enormous computing power to the simple problem being an operating system, with a propensity to fail.  And generate endless pseudo support teaser messages - these must be the same half wits who press the "send" button ;)

Seriously tho many thanks for the cookie refs, reading now...
LVL 16

Expert Comment

ID: 10395690
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: pjedmond {http:#9923847} & Jester_48 {http:#9923927}

Please leave any comments here within the next four days.

EE Cleanup Volunteer

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question