Easiest way to clear the values ​​of all controls in a div using jquery?

I have an added form inside a div that has 3-5 text boxes. I submit the form via ajax and hide the div in its success function ... Now I want to clear all textbox values ​​within the adddiv using jquery?

+2


a source to share


3 answers


If these are only text fields (<input type = "text"> fields), then $ ("form: input"). val (""); would be the easiest way. If you have multiple types of inputs, you should check this.

http://www.learningjquery.com/2007/08/clearing-form-data



Looks at how to create a form cleanup plugin.

+3


a source


$('#form input').attr('value','');
      

Reset radio buttons and check boxes:

$('#form input[type=radio]').attr('checked','');
      

It might be easier to combine this:



$('#form input').attr('value','').attr('checked','');
      

But if this is for all possible choices, this should work too:

$('#form').each(function() {
  this.reset();
});
      

+6


a source


$('input, select', $('#yourForm ')).val('');

      

0


a source







All Articles