Chrome doesn't cache hidden form field values for use in browser history

12,789

Solution 1

You should not rely on this behavior. It is different among browsers, even among browser versions. This behavior is not described in any standards. If you want your fields to have specific values, you can use cookies, or always make requests to the server when page loads, or use more modern methods like local storage (it is not widely supported though).

Solution 2

This problem could be solved using a small trick.

The problem is Form fields with Type=hidden with Dynamically set values are not handled properly by the Chrome Browser.

So the solution is to change the type of the field to text and use some other method to hide the visible text boxes. This could be achieved by surrounding all the text boxes carrying values intended to be hidden by a DEV tag pair and assigning the style as display: none

Then on the page you wont see the text boxes carrying hidden values and it will work properly with JavaScript of the browser.

BEFORE

<input type=hidden name=item_no value=00001>

AFTER

<div style="display: none">
    <input type=text name=item_no value=00001>
</div>
Share:
12,789
Andy McCluggage
Author by

Andy McCluggage

Updated on June 04, 2022

Comments

  • Andy McCluggage
    Andy McCluggage almost 2 years

    I have a ASP.Net web form that contains both text box fields and hidden fields. The hidden field values are modified dynamically using client side JavaScript. Posting the form, inspecting the values and redirecting to another page is all working as expected.

    However, when I use the browser back button to display the previous page then I expect so see that ALL form fields are still populated with the values that were posted.

    In IE and Firefox this is the case for both text and hidden input fields.

    In Chrome this is ONLY the case for text fields. The value of hidden fields is lost.

    Is it true that Chrome never repopulates dynamically set hidden form field values when navigating the browser history?

    I have put a small sample together to demonstrate the problem and can provide that if required. I wanted to first ask the question to see if this is well known behaviour and something I have to accept.

  • Andy McCluggage
    Andy McCluggage over 13 years
    Thanks for the response, even though it saddens me to read it. I’m dealing with an extremely complicated legacy advanced search, and we have been relying on the back functionality to repopulate the criteria. Short term: I’m going to have to hack it until we can slip the rewrite of this page into the backlog. Oh well...
  • avernet
    avernet about 13 years
    This is indeed a Chrome-only behavior, which I find rather strange. I did some research on this, which you can find at: wiki.orbeon.com/forms/doc/contributor-guide/…
  • Andy McCluggage
    Andy McCluggage almost 13 years
    Nice trick. I think I may have even done something similar in the end. It was the kind of system where it didn't bother me to do that. It's days are numbered anyway. I closed my eyes...made the change...and can still sleep at night