Hello Everyone.
I have a html table which if filled by values of an mysql table. This way:
function getCategories(){
$prod = new C_Product();
$cat= $prod->getCategorieenAsArray();
$tr = "";
foreach ($cat as $key => $value){
$tr.="<tr><td> </td><td>$value</td><td><img src=\"images/delete_button.gif\"></td></tr>\n";
}
return $tr;
}
Now I want to be able when i press the delete button to remove that row from the database and to refresh the table so that it's actually removed also from the table on the html page. I want to use for this jQuery and Ajax. That shouldn't be to difficult for me. My question is how to select the row that is going to be deleted? How would the jquery know which img is pressed?
Should i add a class to the img / tr with a value in it? If I use an id I would have to redefine my jquery function for each row that's being added and thus doesn't seem a right solution.
So can anyone please help me further?
Thanks
//edit:
In the mean time I went on my own way to try figure stuff out and I have now a complete ajax call with the correct id.
jQuery(document).ready(function(){
jQuery("img.deleterow").click(function(){
id = jQuery(this).parent().attr("id");
jQuery.ajax({
type: "POST",
data: "id=" +id,
url: "ajax_handler.php",
success: function(msg){
jQuery(this).parent().remove();
}
});
});
});
Now the only problem I have is to remove the tr from the table when the id is deleted in the database. This is how my tr looks like:
$tr.="<tr><td> </td><td>$value</td><td id=\"$key\"><img class=\"deleterow\" src=\"images/delete_button.gif\"></td></tr>\n";