Reputation: 101
I have made a Invoice table with adding and appending row features.
http://jsfiddle.net/fmcbwude/31/
But there's an error. When I add a new row, and start inputting the new "quantity", the value of "Total" cell is filled with the value of the "Total" cell of the first row.
But this error doesn't occur in this project : http://jsfiddle.net/norlihazmeyGhazali/fmcbwude/
.on('keyup', '.qty, .net_rate', function () {
var parent = $(this).closest('.invoice_table');
calculate(parent);
})
function calculate(e){
var q = +$(e).find('.qty').val();
var n = +$(e).find('.net_rate').val();
var sum = 0;
$(e).find('.totalLinePrice').val(q*n);
$('.totalLinePrice').each(function(i,e){
sum += +$(e).val();
});
$('.grand').val(sum);
} ;
What am I doing wrong?
Upvotes: 0
Views: 518
Reputation: 3393
the parent must be the row not the table :
.on('keyup', '.qty, .net_rate', function () {
var parent = $(this).closest('tr');
calculate(parent);
http://jsfiddle.net/fmcbwude/32/
Upvotes: 1