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

5
  • $("#slider-submit").find('input:text, input:hidden, input:password, input:file, select, textarea').val(''); Commented Jun 5, 2015 at 7:10
  • possible duplicate of How to reset (clear) form through JavaScript? Commented Jun 5, 2015 at 7:10
  • Can you show your form? One thing is you are calling reset after return false Commented Jun 5, 2015 at 7: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. Commented Jun 5, 2015 at 7:11
  • Add $('#slider-submit')[0].reset(); in sucess not after return false $('#success').html(response); //$('#success').hide('slow'); $('#slider-submit')[0].reset(); }); Commented Jun 5, 2015 at 7:13

4 Answers 4

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;
Sign up to request clarification or add additional context in comments.

Comments

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;

    });
});

Comments

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

Comments

0

In a normal scenario after posting ajax call using jquery.

$('#MyFormId').reset()

or

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

Hopefully it should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.