February 9th 2010 Reset jQuery Form (4 Lines of Code!)
Clearing a form using jQuery is actually quite simple. I have seen quite a few examples out there on how to do it, but they all seems to use a lot of code. I use the code below to accomplish the reset. It seems to work without any issues. Let me know if you find anything better!
// bind the click event to the reset button on the form
$('#resetbutton').bind('click', function(e){
// get all input controls but buttons, and clear their values
$(':input[type!=button]').val('');
// blur the button (makes it works better in IE)
$(this).blur();
// return false to disable default action for the button
return false;
});
Hope you found this tip helpful. I use this code all the time, so I figured it would help others out there too!
