Reputation: 13
I have five small forms on one page. When the page is loaded via the top menu all fields are blank or default. When the page is loaded via the browser back button the fields retain their previous selection or entry data. What I want to do is have the forms clear down when the page is loaded via the browser back button so no matter how the page is loaded the fields are always blank or default. This is the page - http://www.heat-sink.co.uk/index.php?page=extruded. Thanks
Upvotes: 0
Views: 3484
Reputation: 45
For example, if we have two forms. With the help of the following two functions written in JavaScript, we can reset and submit for those two forms. (Form 1 and Form 2 are two form IDs.)
<script>
submitForms = function(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}
resetForms = function(){
document.getElementById("form1").reset();
document.getElementById("form2").reset();
}
</script>
<input type="submit" value="send " onclick="submitForms()" >
<input type="reset" value="cancel " onclick="resetForms() ">
Upvotes: 0
Reputation: 26
Please provide ID to your forms and in document ready event put below code:
document.getElementById("kk").reset();
Note: here "kk"
is id of form. If you have 5 forms as you mentioned, you have to assign them with different ids and each form you have to reset separately using above code.
Upvotes: 0
Reputation: 913
In your document ready event reset form like below
$(function(){
$("form").reset();
});
I decided to test the above and it didn't work because JQuery has no reset() method but javaScript does. So to use the above, convert the jQuery element to a JavaScript object like
$("form")[0].reset();
But the code below works so you can use it.
$(function(){
$('form').trigger("reset");
});
Upvotes: 4
Reputation: 1286
To reset all forms:
$( document ).ready(function() {
$('form').each(function() { this.reset() });
});
Upvotes: 2