-3

I have a button with id="reset", So when the button is clicked I want to do two things:

  1. The form has to be reset.
  2. Refresh the datatable.


Js/jQuery:

$("#reset").click(function(){
    $("myform").reset();
    var oTable = $('#documentreport').dataTable();
    oTable.fnDraw();
}

This is what I have tried so far. Any help would be appreciated

Colin Cline
  • 1,291
  • 1
  • 12
  • 25
Bala Ji
  • 7
  • 6
  • I assume you're referring to the [DataTables](http://www.datatables.net/) plugin? – Tieson T. Sep 03 '14 at 06:37
  • Also at end you need to close with }); not } – RajivRisi Sep 03 '14 at 06:40
  • 1
    if you want to reset the form: [here](http://stackoverflow.com/questions/16452699/how-to-reset-a-form-using-jquery-with-reset-method), if you want to reset the datatable: [here](http://stackoverflow.com/questions/3207472/datatables-reinitialization-jquery), took me about 7 seconds – Kevin Sep 03 '14 at 06:41
  • Finally i got what i wanted.. Here is how i did it $( "#reset" ).click(function() { $(".target").val("");// target is the class for all the form fields var oTable=$('#documentreport').dataTable(); oTable.fnDraw(); }); Anyway thanks for ur help guys... – Bala Ji Sep 03 '14 at 06:56

1 Answers1

0

refresh database:

Calling $('#table').dataTable().fnDestroy(); will clear the table of dataTable code and allow you to manipulate the table, and then call dataTable on it again.

Reset form: http://jsfiddle.net/8zLLn/

  $('#reset').click(function(){
        $('#myform')[0].reset();
  });

very well answered by shmuel613 and tadiou thank you both.

xxbinxx
  • 1,527
  • 11
  • 18