Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear the form once form submitted [duplicate]

Tags:

jquery

Possible Duplicate:
Resetting a multi-stage form with jQuery

Once the form submitted, response from another page is printed to #GameStorySys. But values entered to the form still stays there. Is it possible for the form values to disappear (but the form should still stay) once the form 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);
                }
        }); 
}); 
like image 435
zurna Avatar asked Oct 25 '22 16:10

zurna


1 Answers

You can clear 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);
    }
  }); 
});
like image 102
Nick Craver Avatar answered Nov 01 '22 18:11

Nick Craver