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

人盡茶涼 提交于 2019-11-30 11:25:45

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

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>

I can't seem to comment, maybe my rep too low but felt this is important to mention.

I just ran into this problem myself in Opera so borrowed Sanesh Fernando's solution which worked around the hidden fields not being reinstated (Thanks Sanesh). However what caused a problem for me was that Javascript fires before the form fields are updated so if you check values with javascript as I was doing then I had to add a setTimeout to ensure Opera updated before I checked the values.

Cookies are as stated another way but what with the ridiculous EU directive on requiring cookie usage agreement from the visitor it's not a solution for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!