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
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
Share Improve this question asked Aug 4, 2009 at 23:53 chicanechicane 2,0813 gold badges20 silver badges15 bronze badges2 Answers
Reset to default 5window.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.
$(':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.