Reputation: 2081
I have a simple form, lets say it takes an email address. Once the form is submitted a message stack notifies the user that their address has been submitted successfully. The issue is that after submitting the address the form field with the email still contains the email address that the user typed in, how would I reset this field? Would I have to use JavaScript for this?
Thank you
Upvotes: 3
Views: 6442
Reputation: 34057
window.onload = function () {
for(var f in document.getElementsByTagName("form"))
f.reset();
}
This would certainly work, assuming you don't have another onload event already set. If you do, just add the inner bit (lines 2 and 3) to it. And of course this is standard JavaScript, it'll work no matter the framework.
Upvotes: 5
Reputation: 61567
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
from this question:
Resetting a multi-stage form with jQuery
Requires jQuery: http://jquery.com
Upvotes: 1