Reputation: 944
Hello I m using jquery validations , my form is validating and submitting successfully but the fields containing the previous data, i want to reset the fields after submitting the form.
the $('#frm').reset(); is not working.
submitHandler: function(form)
{
$.ajax({
url: "contact_submit.php",
type: "post",
data: $("#frm").serialize(),
success:function(response)
{
if(response)
{
$('#msg-valid').html('<img src="img/valid.png">Your form is submited, Thank You !');
$('#frm').reset();
}
else{
$('#msg-error').html('<img src="img/error.png">Your form is not submited');
}
}
});
}
Upvotes: 1
Views: 2973
Reputation: 944
I found that,the following code reset the form after submit.
submitHandler: function(form)
{
$.ajax({
url: "contact_submit.php",
type: "post",
data: $("#frm").serialize(),
success:function(response)
{
if(response)
{
$('#msg-valid').html('<img src="img/valid.png">Your form is submited, Thank You !');
$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
$(':checkbox, :radio').prop('checked', false);
}
else{
$('#msg-error').html('<img src="img/error.png">Your form is not submited');
}
}
});
}
Upvotes: 0
Reputation: 67207
Basically .reset()
is a native javascript function. You are trying to invoke it from wrapped Jquery object. So probabbly it would have caused error in your console
, So in order to access it, first you have to extract the javascript object from the Jquery object then invoke that function like,
$('#frm')[0].reset();
Upvotes: 4