clear input fields on page refresh (Microsoft Edge)

If the input is inside a form element <form id="example"> ... </form> , then you can do something like document.getElementById('example').reset(). You can call this inside window.onload.

HTMLFormElement.reset()


First, thanks for the responses.

I had tried autocomplete='off' (sorry I forgot to mention that), but it didn't seem to work.

Just before checking here for replies, though, I decided to try one other experiment. I added a button to my page which, when clicked, would call a function containing the JavaScript .value = '' statement.

For whatever reason, that worked just fine; it emptied the value and cleared the field, which got me thinking that tying the "reset" to a specific HTML event might be the key. I tried a couple of things that didn't work, but finally I just replaced this:

document.getElementById('input_field').value = '';

. . . with this:

window.onload = function() {
  document.getElementById('input_field').value = '';
  }

. . . and that did it. Every time I refresh the page in either Firefox or Edge, the value is emptied and the field is cleared.

I'm not sure why that worked (like I said, I'm just getting started with this stuff), but there it is.


Add the attribute autocomplete="off" to the <input> tag.

<input autocomplete="off">

This may not work on all browsers. See this site for browser support chart: https://caniuse.com/#feat=input-autocomplete-onoff

If it's not working on Edge try the solution provided on this fiddle by fizzix.

Original post Chrome Browser Ignoring AutoComplete=Off.