views:

314

answers:

1

Most browser cache form input values. So when user refreshes page, the inputs have same values.

Here's my problem. When user clicks Save, server validates POSTed data (e.g. checked products), and if not valid, sends it back to browser. However, as stated above, even if server clears selection for some values, they may still be selected because of browser cache! My data has invisible (until parent item selected) checkboxes, so user may be even not aware that some previous value is still selected, until clicks Save again and gets error message - even though user thinks it's not. Which is irritating.

This can be resolved by doing Ctrl-F5, but it's not even a solution. Is there an automatic/programmatic way to tell browser not to cache form input data on some form/page?

+1  A: 

Are you explicitly setting the values as blank? For example:

<input type="text" name="textfield" value="">

That should stop browsers putting data in where it shouldn't. Alternatively, you can add the autocomplete attribute to the form tag:

<form autocomplete="off" ...></form>
DisgruntledGoat
I talk about checkboxes so I can't set value to "". And, does autocomplete off means not to store form input values "when user presses F5", not only "for dropdown autocompletion list"?
queen3
According to https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion, autcompletion=off affects "Session history caching", at least in Gecko. I will test if it works for what I need.
queen3
@queen3: Yes, checkboxes are a problem since there is no way to explicitly say "not checked". If you're still having problems, you could try `checked="false"`, it may work in some browsers. Another alternative is to use Javascript/jQuery to explicitly untick all checkboxes on page load.
DisgruntledGoat