0

I am trying to do comments so that after submitting the appending the data on the form! and the form is showing the comments that i sent previously. This is my form of html

<table> 
<tr><td>Name :</td><td> <input type="text" id="name"/></td></tr>
<tr><td>Email :</td><td> <input type="email" id="email"/></td></tr>
<tr><td>Comment:</td><td><textarea cols=50 rows=10 id="input_text" placeholder="Discuss here"></textarea></td></tr>
<tr><td></td><td><button id="btn">Submit</button></td></tr>
</table>

and i am sending this form values to db through load() ajax function,

 <script>
   $(document).ready(function(){
$("#btn").click(function(){
    var comments=$("#input_text").val();
    var name=$("#name").val();
    var email=$("#email").val();

 $("#hidden_div").load("insert.php",   {comments:comments,name:name,email:email},function(){
  $("#display").append($("#hidden_div").html());
      });
  } 
    });
  });
 </script>
 <div id="hidden_div" style="display:none"></div>
Mahesh
  • 21
  • 10

2 Answers2

1

just use val to set a new value for each form field, after you call the load function

$("#hidden_div").load(...);
$("#input_text, #name, #email").val('');
Philipp
  • 15,377
  • 4
  • 35
  • 52
0

Use this after your form submitted

$("input , textarea").val("");
Dhaval Panchal
  • 648
  • 6
  • 26