Clear the form after submitting the form

Possible duplicate:
Resetting a multi-stage form using jQuery

After submitting the form, the response on another page is printed on #GameStorySys. But the values ​​entered into the form still remain there. Is it possible for the values ​​of the form to disappear (but the form must remain) after the form is submitted?

$("[name='GameStoryForm']").click(function() { 
        $.ajax({
            type: "POST",
                data: $("#GameStoryForm").serialize(),
                url: "content/commentary/index.cs.asp?Process=EditLiveCommentaryStory&CommentaryID=<%=Request.QueryString("CommentaryID")%>", 
                success: function(output) { 
                $('#GameStorySys').html(output);
            },
                error: function(output) {
                $('#GameStorySys').html(output);
                }
        }); 
}); 
+5
source share
3 answers

You can clean it manually, for example:

$("[name='GameStoryForm']").click(function() { 
  $.ajax({
    type: "POST",
    data: $("#GameStoryForm").serialize(),
    url: "content/commentary/index.cs.asp?Process=EditLiveCommentaryStory&CommentaryID=<%=Request.QueryString("CommentaryID")%>", 
    success: function(output) { 
      $('#GameStorySys').html(output);
      $("#GameStoryForm").get(0).reset();
      //or manually:
      // $("#GameStoryForm :input").not(':button, :submit, :reset, :hidden')
      //                           .val('').removeAttr('checked selected');
    },
    error: function(output) {
      $('#GameStorySys').html(output);
    }
  }); 
});
+3
source

I would do it with javascript:

<script>
document.getElementById(yourFormId).onsubmit = new Function(){this.reset();}
</script>
0
source

reset AJAX, , . reset onsubmit() ( ), ( AJAX click(), submit()).

What you need to do is reset after issuing the AJAX request, that is, after calling $ .ajax () - but not in its callback function called when the request returns:

$("[name='GameStoryForm']").click(function() { 
  $.ajax({
    type: "POST",
    data: $("#GameStoryForm").serialize(),
    url: "content/commentary/index.cs.asp?Process=EditLiveCommentaryStory&CommentaryID=<%=Request.QueryString("CommentaryID")%>", 
    success: function(output) { 
      $('#GameStorySys').html(output);
    },
    error: function(output) {
      $('#GameStorySys').html(output);
    }
  });

  $("#GameStoryForm").get(0).reset();
});
0
source

All Articles