Help - calculate total of multiple input fields
Hello,
I have been working on a small freight calculator, cubic amounts are calculated based on quantity and a formula.
Here is my current JSFiddle
http://jsfiddle.net/weedy/vcD9A/
At the moment, i would like the quantities column (inputs) to be totaled at the bottom in a span element called "totalquantity". I have got the total working for the cubics column.
jquery example, please see full code on jsfiddle http://jsfiddle.net/weedy/vcD9A/
- function total() {
$('.totalcubics').html(function () {
var total = 0;
$('table').find('span').not(this).each(function () {
var n = parseFloat($(this).text());
total += isNaN(n) ? 0 : n;
});
return total.toFixed(2);
});
}
$("#07flute").keyup(function () {
var val = parseFloat($(this).val());
val = (val ? val / 50 * 0.0113 : "");
$("#cubics").text(val);
total();
});
$("#08flute").keyup(function () {
var val = parseFloat($(this).val());
val = (val ? val / 50 * 0.0128 : "");
$("#cubics2").text(val);
total();
});
$("#09Bflute").keyup(function () {
var val = parseFloat($(this).val());
val = (val ? val / 50 * 0.02862 : "");
$("#cubics3").text(val);
total();
});
$("#09Eflute").keyup(function () {
var val = parseFloat($(this).val());
val = (val ? val / 50 * 0.0156 : "");
$("#cubics4").text(val);
total();
});
I am quite a novice, so any solution would be greatly appreciated. Thanks