I'm working on a form that calculates using multiplication and addition, but I can't seem to get the pieces to fall together correctly....
$('.qty').on('keyup', function() {
var sum = 0;
$("tbody tr").each(function(i,o){
total = parseInt($(o).find(".qty").val(), 10) * parseInt($(o).find(".price-integer").val(), 10);
if(!isNaN(total) && total.length!=0) {
$(o).find(".install-total").val(total);
sum += total;
}
});
$("#total-equipment").val(sum);
});
When the user types in a quantity, say 2 in the first column, that should multiply by the figure in the fourth column (3,000) and be outputted into the Install Total column.
Then all the numbers in the Install Total column need to be added up and outputted in the Total Equipment Cost input field.
And finally, the + Installation figures need to add up.
And all this has to happen after the user enters a quantity, which that part works. Yay.
I can't seem to get the syntax right or something! I've been looking at stackoverlow.com's posts for the past few days and nothing is working, so I'm hoping someone could throw me a bone and help me out. I really do appreciate your time.
$(o).find(".qty").val()is one issue, the td doesn't have a value. Try$(o).find("input.qty").val(). You're making the same mistake when you get the price.