How can I delete row tables in mysql using jquery?

I want to delete specific rows in mysql using jquery. It works on the first line, but nothing happens on the second line.

This is my HTML code:

<td><p data-placement="top" data-toggle="tooltip" title="Delete"> <button id="dele_com" class="btn btn-danger btn-xs" name="<?php echo $rows['companyID']; ?>"> <span class="icon-trash"></span> </button></p> </td> 

and this is my jquery code:

 $("#dele_com").on("click", function(event) { var show_id = this.name; alert(show_id); bootbox.dialog({ message: "Are you sure you want to Delete this account ?", title: "<i class='icon-trash'></i> Delete !", buttons: { success: { label: "No", className: "btn-success", callback: function() { $('.bootbox').modal('hide'); } }, danger: { label: "Delete!", className: "btn-danger", callback: function() { $.post('update_delete.php', { 'pid1':pid1 }) .done(function(response){ window.location.href= "modification.php"; }) .fail(function(){ bootbox.alert('Something Went Wrog ....'); }) } } } }); }); 
+5
source share
1 answer

Here you specified id #dele_com , and this will be the same for each line. Therefore, when you click the "Delete" button, it will find the first identifier of your table and click.

You should use a class selector instead of id, then it will work

+4
source

Source: https://habr.com/ru/post/1261403/


All Articles