How to clear a form after the user submits it (

After spending much time looking for a JavaScript way of clearing fields after the user submits, I stumbled upon this page on
Such a simple solution and works perfectly! Thank you Boutell!

<title>A Self-Clearing Form</title>
function clearForms()
var i;
for (i = 0; (i < document.forms.length); i++) {
<body onLoad="clearForms()" onUnload="clearForms()">
<h1>A Self-Clearing Form</h1>
This form data will self-destruct when you leave the current web page.
<form method="post" action="page2.php" name="test">
<input name="field1"/> Field One
<input name="field2" type="radio" value="One"/>One
<input name="field2" type="radio" value="Two"/>Two

<input name="field2" type="radio" value="Three"/>Three
<input name="field2" type="radio" value="Four"/>Four
<input type="submit" value="Submit Form Data"/>

Leave a Reply

Your email address will not be published. Required fields are marked *