I'm working on a web application and want to create something like an invoice calculation, but with sub-groups, so at the end I need the result of the group-totals and the sub-totals.
This is what I got so far: Fiddle
$(function() {
$("#items").keyup(function(event) {
var total = 0;
$("#items .targetfields").each(function() {
var qty = parseInt($(this).find(".quantity").val());
var rate = parseInt($(this).find(".rate").val());
var subtotal = qty * rate;
$(this).find(".subtotal").val(subtotal);
if (!isNaN(subtotal)) total += subtotal;
});
$("#total").html(total);
});
})
Ultimately, I'm working towards something like this:
I have found a lot of examples about invoice calculation but not with groups or sub-totals.
I hoped someone could help me out with a little example.