1

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');                         
            }
        }
    });
}
sfletche
  • 47,248
  • 30
  • 103
  • 119
Devidas Kadam
  • 944
  • 9
  • 19
  • possible duplicate of [How to reset a form using jQuery with .reset() method](http://stackoverflow.com/questions/16452699/how-to-reset-a-form-using-jquery-with-reset-method) – dunli Jun 21 '14 at 05:53

3 Answers3

4

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();
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
0

Try with

$('#frm')[0].reset();

It will clear the form fields

Sridhar R
  • 20,190
  • 6
  • 38
  • 35
0

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');

                    }
                }

            });

        }
Devidas Kadam
  • 944
  • 9
  • 19