May I know how to remove table row for selected row only. For example, If I choose 2 rows to delete, it will delete the chosen rows. I have made this example but I do not know how to get the id's of the chosen row. Below are the example,
jQuery:
$("#delete").click(function(){
var del = $("#delete").val();
var cb=[];
$('.checkBox:checked').each(function(){
cb.push($(this).val()); // id's of selected checkbox to delete
});
$.post('delete-pr.php',
{
del : del,
cb : cb
}, function(data){
$("#result").html(data);
$('#myTable tr:last').remove(); // this will delete last row only
});
});
html:
<table id="myTable">
<tr>
<th><input type="checkbox" name="selectAll" id="selectAll" title="Select All"></th>
<th>Title</th>
<th>Type of Purchase</th>
</tr>
<?php
$sql="SELECT * FROM purchase";
$result=mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
while($row=mysqli_fetch_assoc($result)){
$pr_id=$row['pr_id'];
?>
<tr>
<td align="center"><input type="checkbox" name="del[]" id="checkBox" class="checkBox" value="<?php echo $row['pr_id']; ?>"></td>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['purchase_type']; ?></td>
</tr>
<?php
}
}
?>
</table>