Avatar of diecasthft01
diecasthft01

asked on 

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?
DatabasesJavaScript

Avatar of undefined
Last Comment
Julian Hansen
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lenamtl
lenamtl
Flag of Canada image

Hi,

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
location.reload();

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.
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

You could use Web Storage https://www.w3schools.com/html/html5_webstorage.asp

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.

Regards,
Chinmay.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

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.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo