Return to Snippet

Revision: 37696
at December 15, 2010 09:46 by touffies


Initial Code
/* ------------------------------------------------------------------
    Clears the form data -------------------------------------------- */
    $.fn.clearForm = function() {
        return this.each(function() {
            $(".error", this).removeClass("error");
            $('input,select,textarea', this).clearFields();
        });
    };

    // Clears the selected form elements.
    $.fn.clearFields = $.fn.clearInputs = function() {
        return this.each(function() {
            var t = this.type, tag = this.tagName.toLowerCase();
            if (t == 'text' || t == 'password' || tag == 'textarea')
                this.value = '';
            else if (t == 'checkbox' || t == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = 0;
        });
    };

Initial URL

                                

Initial Description

                                

Initial Title
Clear Form Data

Initial Tags
form, jquery

Initial Language
jQuery