Input forms disappear when selecting the back button.

Good morning. I have a question related to actions using javascript and then using a back button on a submit page. I have a javascript function that allows a user to add additional input fields on a web page. So basically a user has one line that they can add an item and then if they need to add additional items, they hit a button and a new input line shows up. Once they do this up to 5 times, these items will be entered into a database with an action page. All of this works as designed. The submit page does some validating, and asks additional questions so I run the forms data to the submit page. But what I noticed is that if the user selects the back button, the added input fields do not show up on the previous page. Is there a way to make those added input forms stay visible when selecting the back button on the page?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
That is one of the problems with dynamic content.

There are several ways you can get around this if you look around.

For example:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

usually a page will load the data from DB on page load

I don't know how your page work but if the data is saved in DB you will need a way to force a page reload to get the newly data.

There is a simple way to do it using Javascript

Open in new window

if the data is not save then you need a way to temporary saved the data in localstorage or similar way.
Chinmay PatelChief Technical NinjaCommented:
You could use Web Storage

Based on your exact requirement, you can go with localStorage or sessionStorage, add these additional fields on the page(as well as in the web storage) when the user clicks on the back button, on the page load(you might have to use Jquery's ready method), just read those values and populate those fields as required.

Julian HansenCommented:
Save your dynamically added fields to local storage as they are created.
When your form load check local storage to see if anything has been saved there - if it has run the saved fields through your renderer to create them on the form.
When the form is saved to the db clear local storage.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.