I have a number being copied from one field to another. I then have a calculation being done using the number that was just copied over. For some reason, though, the calculation is running before the number is copied over. Here is my code:
$(document).ready(function () {
$(document).ready(function () {
$('.numberinput input').on('change', function() {
$('[name="Field84(1)"]').val($('.numberinput input').val());
});
}).on('change','.cf-table-block input', sumtotal);
function sumtotal() {
var sum = 0;
$('td.sum6').each(function () {
var s = 0;
$(this).find('input').each(function () {
s += parseNumber($(this).val());
});
$(this).find('.subtotal input').val(s);
sum += s;
});
$('.total6 input').val(sum);
if ($('.subtotal').length > 0) rowtotal();
}
function rowtotal() {
var sum = 0;
$('.cf-table-block tbody tr').each(function () {
var s = 0;
$(this).find('.sum6 input').each(function () {
s += parseNumber($(this).val());
})
$(this).find('.subtotal input').val(s);
sum += s;
});
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});
Here is a screen shot:
So I need -1 from "Single Line" to copy into "Field84(1)" which is the editable field. Right now the calculation is doing 3 + 0 = 3. And then it is copying -1 in... so it's not part of the calculation. How do I make the calculation wait until the number has been copied in?