JavaScript DHTML/Form Control/Form Reset
form.reset() and form.submit() Methods
<source lang="html4strict">
<html> <head> <title>Registration Form</title> </head> <body> <form name="entries" method="POST" action=""> Enter your first name:<input type="text" name="firstName" id="firstName" />
Enter your last name:<input type="text" name="lastName" id="lastName" />
Enter your address:<input type="text" name="address" id="address" />
Enter your city:<input type="text" name="city" id="city" />
<input type="radio" name="gender" id="gender1" checked="checked"/>Male <input type="radio" name="gender" id="gender2" />Female
<input type="checkbox" name="retired" id="retired" />I am retired
</form>
<a href="javascript:document.forms[0].submit()"> <img alt="image" src="submit.jpg" height="25" width="100" border="0" /></a> <a href="javascript:document.forms[0].reset()"> <img alt="image" src="reset.jpg" height="25" width="100" border="0" /></a>
</body> </html>
</source>
Reset the fields in a form
<source lang="html4strict">
<html> <head> <script type="text/javascript"> function formReset(){
var x=document.forms.myForm x.reset()
} </script> </head> <body> <form name="myForm">
Enter some text in the text fields and then press the "Reset form" button
<input type="text" size="20">
<input type="text" size="20">
<input type="button" onclick="formReset()" value="Reset form">
</form>
</body>
</html>
</source>
The onreset and onsubmit Event Handlers
<source lang="html4strict">
<html> <head> <title>Submit and Reset Confirmation</title> <script type="text/javascript"> function allowReset() {
return window.confirm("Go ahead and clear the form?");
} function allowSend() {
return window.confirm("Go ahead and mail this info?");
} </script> </head> <body> <form method="POST" enctype="text/plain" action="mailto:a@b.ru" onreset="return allowReset()" onsubmit="return allowSend()"> Enter your first name: <input type="text" name="firstName" id="firstName"/> Enter your last name: <input type="text" name="lastName" id="lastName"/> Enter your address: <input type="text" name="address" id="address"/> Enter your city: <input type="text" name="city" id="city" /> <input type="radio" name="gender" id="gender1" checked="checked" /> Male <input type="radio" name="gender" id="gender2" />Female <input type="checkbox" name="retired" id="retired" />I am retired <input type="reset" /> <input type="submit" /> </form> </body> </html>
</source>