Tuesday, March 03, 2009

Using JQuery Clearing Form

Few days back I download JQuery’s UI Plug-in which came with bunch of nifty UI’s, however the one particular I was interested in was “Dialog box” plug-in.

After playing with it a little bit I realized that I need to clear the form after I close, and process the dialog box's form information. So I searched for built-in JQuery function that can do that but no luck. So, after searching just little bit I came across this page http://www.learningjquery.com/2007/08/clearing-form-data. Well the article did really nice job explaining, but the solution give in this article did not work, however after reading comments on that page I saw one comment with following piece of code that work perfectly for me.

//this is to Clear All the field with in perticular Element
$.fn.clearForm = function() {
  $( this ).
    find( ':text, :password, textarea' ).
      attr( 'value', '' ).end().
    find( ':checkbox, :radio' ).
      attr( 'checked', false ).end().
    find( 'select' ).
      attr( 'selectedIndex', -1 );
};

No comments:

Post a Comment