Friday, September 24, 2010

Simple reusable clear form function in using jquery?

I ve created a function which clears the form without writing much javascript code.

$.fn.clearForm = function() {
return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form') {
        $('td.status', this).empty();
        return $(':input', this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea' || tag ==
        this.value = '';
    else if (type == 'checkbox' )
        this.checked = false;
    else if (tag == 'select')
        this.selectedIndex = -1;


and just call this as,

function clearaddform() {

and now you can just call clearaddform function from your button. 


  1. Pretty part of content. I just stumbled upon your site and in accession capital
    to claim that I acquire in fact loved account your weblog
    posts. Any way I will be subscribing for your feeds or even I fulfillment you get right of entry to persistently rapidly.

    Here is my homepage; Male enhancement

  2. You’ve performed an excellent waiting for your next blog. SEO Expert in Pakistan