Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reset a form after submit?

Tags:

javascript

php

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

like image 531
chicane Avatar asked Feb 26 '26 03:02

chicane


1 Answers

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.

like image 145
Ricket Avatar answered Feb 28 '26 16:02

Ricket