2

i have a script to send email via Ajax php code is working well but i also want to reset form after send email here is my jquery code

       <script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){

$('#slider-submit').click(function(){
    $('#success').text('Sending...');

$.post("send.php", $("#slider-form").serialize(),  function(response) {   
 $('#success').html(response);
 //$('#success').hide('slow');


});
return false;
$('#slider-submit')[0].reset();

});

});
</script>

please tell me how is it possible i also used reset method but not working at all

Epodax
  • 1,828
  • 4
  • 27
  • 32
Ahsan Malik
  • 111
  • 1
  • 10
  • $("#slider-submit").find('input:text, input:hidden, input:password, input:file, select, textarea').val(''); – kamlesh.bar Jun 05 '15 at 07:10
  • possible duplicate of [How to reset (clear) form through JavaScript?](http://stackoverflow.com/questions/3786694/how-to-reset-clear-form-through-javascript) – Saty Jun 05 '15 at 07:10
  • Can you show your form? One thing is you are calling reset after return false – Zee Jun 05 '15 at 07:10
  • 1
    Your reset line (`$('#slider-submit')[0].reset();`) is after the return statement, so it is not called. Append it to the ajax success function. – kosmos Jun 05 '15 at 07:11
  • Add $('#slider-submit')[0].reset(); in sucess not after return false $('#success').html(response); //$('#success').hide('slow'); $('#slider-submit')[0].reset(); }); – Manoj Jun 05 '15 at 07:13

4 Answers4

2

You are almost near to your goal, you just need to change the order of your statements (first reset the form, and then return false) in your script, that is as follows.

change

return false;
$('#slider-submit')[0].reset();

to

$('#slider-submit')[0].reset();
return false;
Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36
1

Your reset line ($('#slider-submit')[0].reset();) is after the return statement, so it is not called. Append it to the ajax success function (assuming that the form id is ´slider-submit´).

$(document).ready(function(){
    $('#slider-submit').click(function(){
        $('#success').text('Sending...');

        $.post("send.php", $("#slider-form").serialize(),  function(response) {   
            $('#success').html(response);
            //$('#success').hide('slow');

            $('#slider-submit')[0].reset();
        });
        return false;

    });
});
kosmos
  • 4,253
  • 1
  • 18
  • 36
0

There are different methods, one possible is to trigger the reset event.

Assuming that your form id is ´slider-submit´

$('#slider-submit').trigger('reset');
Mario Araque
  • 4,562
  • 3
  • 15
  • 25
0

In a normal scenario after posting ajax call using jquery.

$('#MyFormId').reset()

or

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

Hopefully it should work.