Reset your form after submit using jQuery


After you submit a form, you reset it with the following code:

 $("form#myform")[0].reset();

For example on my Magic8Ball website, I created a function to submit the form and reset it immediately, clearing out the input elements.

 var  formData = $("#form").serializeArray();
  $.ajax({
    url : "speaktome.php",
    type: "POST",
    data : formData,
    success: function(result)
    {
      $(".youranswer").hide().html('

' + result + '

').fadeIn(5000); $.ajax({url:"update.php",success:function(result){ $(".freshdata").hide().html(result).fadeIn(); $("#form")[0].reset(); // Resets Input }}); } });
,

Leave a Reply

Your email address will not be published. Required fields are marked *