How to prevent browser to re-set inputs on page refresh?

Viewed 1704

As you know, when we have inputs in our HTML forms (checkbox, input or textarea), when we refresh (with f5 for example) Firefox sets the filled values. What should I do to prevent this?

I expect all my fields would be blank and default checkboxes and select inputs in all pages, but when I reload, the browser sets them to filled values.

4 Answers

You can add attribute autocomplete="off" to form element. But it will also disable autocomplete form inputs after focusing them. Which may be unwanted.

Use it is in your form tag

<form autocomplete="off" action="#" method="get">

and for fire fox, you should try it (individual form inputs)

<input type="password" autocomplete="off"> 

If all the input fields are in a form field you can simply use .reset() and run it after the page load to reset all the form fields.

if (document.readyState === "complete") {
 document.getElementById("myForm").reset();
}

You can use jQuery:

$(function () {
  $('#inputId').val('');
});
Related