Setting default select option and then remembering it

Hi,

I have a drop down with time values in. I want to set the defaut value to 00:00.

I have done this using this:


//set the hours to 00
					$(" select[name='bkHour']").val("00");
					$("select[name='bkMinute']").val("00");
					$("select[name='retHour']").val("00");
					$("select[name='retMinute']").val("00");

It works, but it I select a new time, e.g 20:00 and then go to the next page and then back, it reverts to 00:00 again. Is there an easy way I can keep the new time selected?

Thanks!

Hi,

There sure is :slight_smile:

HTML5’s storage API would be the way to go.
You would set a key/value pair every time the user altered the dropdown, then on the next page you would write a small function to retrieve this key/value pair and set the new value of the dropdown accordingly.

I wrote an article on how to do that recently. Maybe it’ll help.

Also, you can use the selected attribute to set the initial value of the dropdown. No need for JS.