I have created a table that grows dynamically when the user enter some values using input and select fields. This is done by the append from jquery. This is the table id="customFields":
===============================================
| ID | CLASS | PRICE | QTY | DELETE |
===============================================
This is the jQuery script that I use to append lines and add information to the table:
var index = 0;
$("#addPRICE").click(function(){
index++;
var id_value = $("#pack_price").val();
var price_qty= $("#price_qty").val();
//alert(id_value);
$.ajax({
type:"POST",
url:"get_mt_pricelist.php",
data:{mt_id: id_value},
dataType:"json",
success: function(data){
if(data.success=="true"){
$("#customFields").append('<tr id="'+index+'" valign="top"><td align="center"><input type="text" class="code1" id="customID" name="customID[]" value="'+id_value+'" size="3" readonly="readonly"/></td><td><input type="text" class="code2" id="customCLASSE" name="customCLASSE[]" value="'+data.multi_classe+'" readonly="readonly"/></td><td><input type="text" class="code3" id="customPRICE" name="customPRICE[]" value="'+data.multi_price+'" readonly="readonly"/></td><td align="center"><input type="text" class="code4" id="customQTY" name="customQTY[]" value="'+price_qty+'"/></td><td valign="middle" align="center"><a href="javascript:void(0);" class="remCF">Delete</a></td></tr>');
});
});
Everything is working fine, the fields are added normally. I get some values from a MySQL database using the ajax and everything. I created a DELETE class called remCF, so when the user clicks on it the actual row will be removed. Also I have an index that gives to each an id number. I would like to catch the value in the cells PRICE and QTY and pop them in a alert msg when the user click on DELETE, then proceed with the remove().
This is what I did:
$("#customFields").on('click','.remCF',function(){
alert($(".code3").val());
alert($(".code4").val());
$(this).parent().parent().remove();
});
The problem is: The alert shows only the value of the first row for any DELETE that I press. Even using CLASS instead of ID. How can I get the right value for the DELETE row that I am clicking?
Thanks
HTML?