Jump to content
HawkDev

Repopulating Form on Reload

Recommended Posts

I have an online form, which has various dropdown lists. One of these is for names of clients, one is for the location, one is for time of appointment, etc. It also has a function to add items onto the dropdown lists if it is a new client. This means that the page has to be reloaded to repopulate the dropdown list with the new client name.

However, there are a lot of different dropdown lists on the form, and if the page is reloaded, I want the particular selections that the user has already made to be reloaded when the page is reloaded, so that they do not have to start again just because one dropdown list needed to be edited.

Can you please explain how to do this? Thank you.

Share this post


Link to post
Share on other sites

Do you want to do all of that in Javascript?  If so, put a handler on each dropdown that runs when the value is changed, and save the new value.  When the page is loaded check for that saved data and set the values of each field.

Share this post


Link to post
Share on other sites

Thank you. I understand that I can use an event handler like ‘onchange’. That is not difficult. However, what I am struggling with is how to save the data between the change of choice in the drop down menu, and the reload of the page. 

Share this post


Link to post
Share on other sites

It's probably best to use localStorage, but you could also use cookies as a data store.

Share this post


Link to post
Share on other sites

I tried using local storage, but I can’t seem to get the system to store the data, and then recall it on reload. Can you please give me a clear example of how this would work for multiple variables?

Share this post


Link to post
Share on other sites

It is ok. I have managed to test a scenario using sessionStorage, and get the data to be recalled after a page refresh. I will now try to apply this to my situation. 

Share this post


Link to post
Share on other sites

localStorage is just like sessionStorage, but sessionStorage only lasts while they're on your site, it won't be there if they come back.  localStorage will.  It's exactly the same to use it though, the difference is persistence.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...