jQuery Function to All Clear Form Data

Pretty useful jQuery Function to clear all form data which I found on Karl Swedberg’s website. It simply removes all data from the form including text inputs, select boxes, radio buttons, checkboxes etc… There are two versions and the second version is probably more useful as you can apply it directly to the DOM element as a jQuery function.

Free JavaScript: Novice to Ninja Sample

Get a free 32-page chapter of JavaScript: Novice to Ninja

Al

Or, you know, use a input type=”reset”.

Developer

555, not difference

Davide Nastri

I love you

Brock

No, you can’t. Because if you have defaults prepopulated (for example the second option in a select) and you click reset, those defaults will be selected again. This does a proper clear, which is why it is so useful.

chz

Also found this simple snippet that will do the work:

$(‘#form’).trigger(‘reset’);

http://jquery4u.com/ jQuery4u

$(“form”).clearForm(); // with the plugin
$(“form”)[0].reset();
$(‘form > input[type=reset]‘).trigger(‘click’); //with a reset button in the form set to display: none;