I have a big problem with the functionality in Firefox that keeps data that the user have filled in on reload F5. If i use Ctrl+F5 the forms are cleared and this is great. My problem is that not all my users know that this is what they have to do to force the input cleanup. Is there a way in the html or response headers to tell Firefox to not keep the data in the forms?
- 3What about making a button that clears the forms? That seems easier for users to understand then letting them push f5Ruben– Ruben2011-09-11 09:15:07 +00:00Commented Sep 11, 2011 at 9:15
- 3Most users want to keep the form data on reload...JJJ– JJJ2011-09-11 09:19:10 +00:00Commented Sep 11, 2011 at 9:19
- 8My problem is that many of my inputs are calculated and on reload the data becomes inconsistent if not everything is reset.Andreas– Andreas2011-09-11 09:21:36 +00:00Commented Sep 11, 2011 at 9:21
- 2You could also recalculate everything on postback.Ruben– Ruben2011-09-11 09:33:26 +00:00Commented Sep 11, 2011 at 9:33
- 2Suggesting users switch browsers has to be a last ditch solution.jawsware– jawsware2022-08-18 15:25:08 +00:00Commented Aug 18, 2022 at 15:25
10 Answers
Just add autocomplete="off" to your forms and you will solve the problem.
<form autocomplete="off"> It can also be added individual items.
<input type="text" autocomplete="off"> jQuery to solve this on all inputs and textareas
$('input,textarea').attr('autocomplete', 'off'); 8 Comments
Instead of going through all inputs you may also just add the attribute to your form-element like so:
<form method="post" autocomplete="off">...</form>
However the above mentioned methods on domReady did not work for me...
2 Comments
In case you want to keep the autocomplete feature of the browser (see other valid answers), try adding the name attribute to the form and give it a random value. It has worked for me:
<form id="my-form" name="<random-hash>"> ... </form> 4 Comments
/*reset form elements (firefox saves it)*/ function resetElements() { var inputs = document.querySelectorAll('input[type=text]'); //you get the idea.....you can retrieve all inputs by tag name input for(var i = 0; i < inputs.length; i++) { document.getElementsByTagName('input')[i].value = ""; } var textareas = document.getElementsByTagName('textarea'); for(var i = 0; i < textareas.length; i++) { document.getElementsByTagName('textarea')[i].value = ""; } } Call this function onload.
1 Comment
autocomplete="off" also disables the suggestions.I think easier and quicker way to do that is
$('input,textarea').attr('autocomplete', 'off'); 1 Comment
I tried the shortened solution above, but it didn't clear the value of the select boxes on my page.
I ended up modifying it slightly and now all input types on the page are cleared regardless of type:
var allInputs = $(":input"); $(allInputs).attr('autocomplete', 'off'); So to make this run onload I just put it in the ready() method:
$(document).ready(function () { var allInputs = $(":input"); $(allInputs).attr('autocomplete', 'off'); }); 1 Comment
one of my colleagues recommended that we should use a random string as the name of the form. It works very well if you don't use the name attribute of the form.
it is an example from the sf1 form builder:
public function renderFormTag($url, array $attributes = []) { .. $attributes['name'] = isset($attributes['name']) ? $attributes['name'] : bin2hex(random_bytes(16)); .. }