I have a form. When I click Refresh in browser, form options stay cached in IE. How can I programmatically force page reload with JS or JQ?
Asked
Active
Viewed 237 times
0
-
`$(":input").val("")` ? - EDIT: `form.reset()` is the way to go as per linked dupe questions. – MDEV Oct 10 '13 at 16:25
-
possible duplicate of [How to reset (clear) form through javascript?](http://stackoverflow.com/questions/3786694/how-to-reset-clear-form-through-javascript) – bPratik Oct 10 '13 at 16:25
-
possible duplicate of [Is it possible to clear a form an reset (reload) the page with one button?](http://stackoverflow.com/questions/6666363/is-it-possible-to-clear-a-form-an-reset-reload-the-page-with-one-button) – scrappedcola Oct 10 '13 at 16:26
-
@SmokeyPHP - you gotta be kidding me?!?!? – bPratik Oct 10 '13 at 16:26
-
@bPratik Nope, just completely forgot about `form.reset()` ROFL - will at least work on inputs that aren't in forms, so.. might as well leave it there – MDEV Oct 10 '13 at 16:27
-
Take a look at this SO answer: http://stackoverflow.com/a/13707898/791952 – Nikita Silverstruk Oct 10 '13 at 16:30
3 Answers
1
Plain javascript:
form.reset();
You can access your form like this
var form = document.forms["your_form_name"];
To perform this on every page reload wrap it in onload event handler, like this:
jQuery (the easiest one)
$(document).ready(function() {
document.forms["your_form_name"].reset();
});
or plain javascript
var form = document.forms["your_form_name"];
var handler = function () {
form.reset();
};
if (form.addEventListener) {
form.addEventListener("load", handler, false);
} else if (form.attachEvent) {
form.attachEvent("onload", handler);
} else {
form["onload"] = handler;
}
or
<body onload="document.forms['your_form_name'].reset();">
(...)

matewka
- 9,912
- 2
- 32
- 43
0
Ideally, you'd use form.reset()
as suggested in this answer
with jQuery:
$('form')[0].reset();
Or without jQuery:
document.forms[0].reset();
Having said that, if those values that you see are being prefilled by the browser as part of it's autocomplete feature, you can disable it by using the techniques suggested in this answer:
Form level:
$('form').attr( "autocomplete", "off" );
Individual element level:
$('inputSelector').attr( "autocomplete", "off" );