Saturday, 3 August 2013

Clear Form Fields Using JQuery



function clear_form_elements(ele) {


    $(ele).find(':input').each(function() {

        switch(this.type) {

            case 'password':

            case 'select-multiple':

            case 'select-one':

            case 'text':

            case 'textarea':

                $(this).val('');

                break;

            case 'checkbox':

            case 'radio':

                this.checked = false;

        }

    });


}

The buttons


<input onclick="clear_form_elements(this.form)" type="button" value="Clear All" />