I have a code that works in .click() but that only works for the first row.
I need to use the same ID as the data is dynamically generated.
code perfectly works for first row .. and grabs the TR ID but doesnt work for 2nd row or so.
<tr id="25">
<td>25</td>
<td>asd</td>
<td>gjkhgkj</td>
<td></td>
<!-- more td's -->
<td id="edit" name="25">Edit</td>
<td id="delete" name="25">Delete</td>
</tr>
<tr id="24">
<td>24</td>
<td>hhh</td>
<td></td>
<!-- more td's -->
<td id="edit" name="24">Edit</td>
<td id="delete" name="24">Delete</td>
</tr>
The function to delete the customer data:
$('#delete').click(function(e) {
var bid = this.id; // button ID
var customerid = $(this).closest('tr').attr('id'); // table row ID
$.ajax({
type: "POST",
url: "delete.php",
data: "id="+customerid+"",
success: function(msg){
// $('#'+customerid).css({backgroundColor: 'red'});
$('#'+customerid).remove();
alert("Sucessfully Deleted.")
// $('#tabledata').load('load.php');
}
});//end of $ajax
if your has an ID which is the database ID which must be taken as an action in your AJAX stream, then try the following:
Of course, after that, you can do whatever you want 😉