I have an add form inside a div which has 3-5 textboxes.. I submit the form via ajax and hide the div in the success function of it... Now i want to clear all the values of textboxes within the adddiv using jquery?
views:
181answers:
3
+1
A:
$('#form input').attr('value','');
Resetting radio buttons and checkboxes:
$('#form input[type=radio]').attr('checked','');
Might be easier to combine that to:
$('#form input').attr('value','').attr('checked','');
But if it's for all the possible options, this should work too:
$('#form').each(function() {
this.reset();
});
Alec
2010-05-19 19:16:28
@Alec what if my form has select,checkbox and radio..
Pandiya Chendur
2010-05-19 19:19:02
Became a long comment :) Edited the answer.
Alec
2010-05-19 19:29:44
+1
A:
If they're just text boxes (<input type="text"> fields), then $("form :input").val(""); would be the easiest way. If you have multiple types of inputs, though, you should check this out.
http://www.learningjquery.com/2007/08/clearing-form-data
It walks through how to create a plugin for clearing forms.
RussellUresti
2010-05-19 19:22:02