Reset form on back button

I have a form with a fair amount of JS. Two fields are shown initially, and then depending on what is chosen, other fields appear. (It was too complex to use conditional fields, so it’s all in JS.)

If the user submits the form without filling out a required field, I keep the values and re-show the appropriate fields. Otherwise, they’re hidden on load.

It looks like people can submit the form and then hit the back button though. It keeps the values loaded, they can change any and then resubmit.

Is there a way to clear the page if the user uses the back button?

Thank you!

I would also like to know the answer to this. My submit button doesnt work if the user goes back and the form is pre-filled because of all the confirmation logic. Would be better if the forms reset on “back”…

We’re trying this and it seems to work at least in Chrome:

if ( performance.navigation.type == 2 ) {
   location.reload( true );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.