Javascript Form How to - Call form.reset() and form.submit() Methods to reset and submit a form








Question

We would like to know how to call form.reset() and form.submit() Methods to reset and submit a form.

Answer


<!--  ww  w  . j a v  a 2 s .c om-->
<html> 
<body> 
<form name="entries" method="POST" action=""> 
First name:<input type="text" name="firstName" id="firstName" /> 
<p>Last name:<input type="text" name="lastName" id="lastName" /></p> 
<p>Address:<input type="text" name="address" id="address" /></p> 
<p>City:<input type="text" name="city" id="city" /></p> 
<p><input type="radio" name="gender" id="gender1" checked="checked"/>Male 
<input type="radio" name="gender" id="gender2" />Female</p> 
<p><input type="checkbox" name="retired" id="retired" />I am retired</p> 
</form> 
<p><a href="javascript:document.forms[0].submit()">
  <img alt="image" src="http://www.java2s.com/style/download.png" height="25" width="100" border="0" /></a> 
  <a href="javascript:document.forms[0].reset()">
  <img alt="image" src="http://www.java2s.com/style/download.png" height="25" width="100" border="0" /></a></p> 

</body> 
</html>

The code above is rendered as follows: