0

I have the following html code of datatable rows which are dynamically generated using php

<tr>
  <td><input type='checkbox' name='post[]' value="1"></td>
  <td>21-Apr-2014</td>
  <td>TEST</td>
  <td>merchant.inloc8.com</td>
  <td>coupon</td>
  <td>mmmq.com/id/rt7WLskQq2lLlO2kTN</td>
  <td>abc.com/response.php (default)</td>
  <!--<td align='center' width='30'><a data-toggle='modal' href='#' ><i class='icon-remove text-danger'></i></a></td> -->
</tr>
<tr>
  <td><input type='checkbox' name='post[]' value="2"></td>
  <td>21-Apr-2014</td>
  <td>say nw</td>
  <td>abcdefg.com</td>
  <td>abc</td>
  <td>mmmq.com/id/lbruxjFl6PitP25vTN</td>
  <td>abc.com/response.php (default)</td>
  <!--<td align='center' width='30'><a data-toggle='modal' href='#' ><i class='icon-remove text-danger'></i></a></td> -->
</tr>

When a checkbox is selected,I wanted to identify the row and delete that row in the backend.I think this can be done using ajax.But no idea.please help

Barmar
  • 741,623
  • 53
  • 500
  • 612
Piya
  • 1,134
  • 4
  • 22
  • 42
  • you need to learn ajax https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started – Jo E. May 03 '14 at 05:49
  • Question can help you http://stackoverflow.com/questions/14475096/delete-multiple-rows-by-selecting-checkboxes-using-php – Gopal Joshi May 03 '14 at 05:52

3 Answers3

1

See this example

Checkboxes.

<input type="checkbox" value="1" name="letter[]" />
<input type="checkbox" value="2" name="letter[]" />
<input type="checkbox" value="3" name="letter[]" />
<input type="button" id="btn_" value="submit" />

When the button is clicked you can get the values of the selected checkboxes as an array and pass it to the ajax call,

$("#btn_").on('click', function () {
    arr=[];
    var arr = $("input[name='letter[]']:checked").map(function() { 
            return this.value; 
          }).get();
    $.ajax({
   type: "POST",
   data: {arr:arr},
   url: "action.php",
   success: function(msg){
     alert("success");
   }
});
});

You will get the values in action.php and delete the rows there. You can change the alert("success");to the callback you want to get.

Vishnuraj V
  • 2,819
  • 3
  • 19
  • 23
0

serialize form data , pass to controller , delete entries. full outline here

Community
  • 1
  • 1
sjt003
  • 2,407
  • 5
  • 24
  • 39
  • 1
    If you're just going to refer to another question, flag it as a duplicate rather than posting it as an answer. – Barmar May 03 '14 at 06:15
0

Look, I'm giving you the logic only. If I give the code, you will not learn anything.

Well, set the checkbox value to the $id of the Table, and once you click submit, check all $ids which are checked, and run a loop to delete the $ids with a query.