php - Deleting a row from dynamic table when click on image -


i working on php/mysql grid list 2 little icons, 1 expected delete actual register , remove row , other supposed redirect user page opening details of selected register. how code looks like:

php:

$output .='<tr id="'.$id.'">'; $output .='<td align="center">'.$expiration_date.'</td>'; $output .='<td>'.$title.'</td>'; $output .='<td>'.$title_pt.'</td>'; $output .='<td align="center">'.$last_update.'</td>'; $output .='<td align="center">'.$active_pack.'</td>'; $output .='<td align="center" class="icon_grid"><a id="edit" title="open register." href="special_pack_open.php?id='.$id.'"><img src="images/write2.gif" width="16" height="16" /></a></td>'; $output .='<td align="center" class="icon_grid"><a id="delete" title="delete register." href="#"><img src="images/trash.gif" width="16" height="16" /></a></td>'; $output .='</tr>'; 

jquery:

<script type="text/javascript"> $(document).ready(function() {     $('table tr[id]').click(function(){         $(this).closest("tr").remove();         var obj = $(this);          $.ajax({            type: "post",            url: 'delete_package.php',            data: { pk_id: obj.attr("id")},            datatype: "json",            success: function(data, evt) {            if (data.success == "true") {                alert('the record has been deleted successfuly!');            } else {                alert('error');            }            }         })     }) }) </script> 

everything working good. when click in trash.gif, deletes register , remove row. thing when click on write2.gif (second link) supposed go next page, same action delete does! how can change jquery code make understand 1 link dedicated delete register?

thank you.

$("table tr[id]") selector tr descendant of table has id attribute @ all. need more specific selector.

as have many rows, should using class instead of id edit/delete.

$(".delete").on("click", function () { /* code */ 

you may need delegate event

$("#id-of-table").on("click", ".delete" 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -