Is it possible to clear a form and reset (reload) the page with one button?
you can simply redirect page to current location with this code:
$('[data-command="reset"]').click(function () {
window.location.href = window.location.href;
}
<input type="button" value="Clear Results" data-command="reset">
I'm a fan of @MikeyHogarth's suggestion since it's called regardless of how the page is refreshed. This is one of those rare times that I find straight javascript to be simpler than jquery so I just wanted to add the code for that.
$(document).ready(function () {
resetForms();
});
function resetForms() {
document.forms['myFormName'].reset();
}
This uses the form name attribute, and if you'd prefer using the form id attribute use this instead:
document.getElementById('myFormId').reset();
If you want the functionality of both of the snippets you posted, you can simply combine them.
<input type="reset" value="Reset" onClick="window.location.reload()">
using JQuery, do something like this on the page;
$(document).ready(function () {
resetForms();
});
function resetForms() {
for (i = 0; i < document.forms.length; i++) {
document.forms[i].reset();
}
}
and then just use your second input, forms will auto refresh when the page loads back up.