# "how to change calculation when the row is removed from a table" Code Answer

3
``````     \$(document).on('change', 'tr td:nth-child(6), tr td:nth-child(5), tr td:nth-child(4)', .
'remove3'
function() {
var total = 0;
var sqty = 0;
var tr = \$(this).parent();
var qty = tr.find('td:nth-child(4)').find('input').val();
var rate = tr.find('td:nth-child(5)').find('input').val();
var amount = qty * rate;
tr.find('td:nth-child(6)').find('input').val(amount);

var tbody = tr.parent();

\$(tbody).find('tr').each(function() {
total += number(\$(this).find('td:nth-child(6)').find('input').val());
sqty += number(\$(this).find('td:nth-child(4)').find('input').val());
});

\$('#tietotal').val(total);
\$('#sqty').val(sqty);
\$('#grandtot').val(total);
})

script to create a next row automatically:

\$('.tb3').on('keydown', 'input', function(e) {
var keycode = e.keycode;
if (keycode !== 9) return;
var \$this = \$(this),
\$lasttr = \$('tr:last', \$('.tb3')),
\$lasttd = \$('td:last', \$lasttr);
if ((\$(e.target).closest('td')).is(\$lasttd)) {
var cloned = \$lasttr.clone();
cloned.find('input').val('');

\$lasttr.after(cloned);
}
});

script to delete row:

\$(document).on('click', '.remove3', function() {
var trindex = \$(this).closest("tr").index();
if (trindex > 0) {
\$(this).closest("tr").remove();
\$('.qty').trigger('change');
} else {