I stumbled across a very simple web form that included 5 select boxes.
In my endless pursuit of providing forms that are actually easy to use and to make my web forms users life happier, I wondered how can I improve that form , so I figured why not save the customers last select box selections , so that they their old selection would be initialized by default each week they when come back to re-submit the form.
I Looked for some open source javascript client that keeps this information as cookies. Couldn't find one , so had to make one.
I tried to have it as simple as possible so all you have to do is to add an additonal attribute like so:
<select id="sel1" onChange="UpdatePersistancy()" savestate="1"> and calling the update and initialize function of course.
The solution is based on scanning the
select tags looking for
savestate attributes, than creating a cookie for each one that should be saved, and storing the value in the cookie. The initializer functions (this should be called when the page loads) also scans the select tags and try to look for an appropriate cookie with a value. If one was found than it just initializes the selection. I'm keeping the inner text rather than the index or the value since I figured that indexes can change and so does internal value. The only thing that's left unchanged and visible to the customer is actually the option's inner text.
It's
here if you need this kind of a solution (if you want to save the selection box state). Although it doesn't support multiple selection , just one. And there are some other improvements that can be made (maybe also extending this to radio buttons, check boxes, etc)
Enjoy.