Using jQuery, how can I reset a form? I can do this using traditional JavaScript but I do not know how to do it with jQuery. Please test the example below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Demo</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script><script type="text/javascript">$(document).ready(function() { $('#abc').val(''); $('#xyz').val('555'); $('p a#reset1').click(function() { document.getElementById('myform').reset(); }); $('p a#reset2').click(function() { $('#myform').reset(); });});</script></head><body><form action="/" method="get" id="myform"><input name="abc" type="text" value="Hello" id="abc" /><input name="xyz" type="text" value="" id="xyz" /></form><p><a href="#" id="reset1">Reset Form using JavaScript</a></p><p><a href="#" id="reset2">Reset Form using jQuery</a></p></body></html>
check if you like the following :
Open in new window
test page : http://jsfiddle.net/wLhkY/2/