$(document).ready(function () {
var c1, r1, r2, r3, r4, r5, r6, r7, r8, t1, t2, t3, t4, b1, b2, b3, b4, b5, b6, b7, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s14, ,s15, s16, s17, s18, s19, s20, e1, e2, e3, e4, e5, e6, e7, e8, tr, tcc, tpc, te, cd, ts, ttp, ttpi, tss, ;
if ($('#form_70304').length) { // Replace XXX with your form ID
$(document).change(function () {
r1 = $('#element_5').val();
r2 = $('#element_6').val();
r3 = $('#element_7').val(); // Here we are setting each of these elements to an assigned variable which will hold its value to calculate later.
r4 = $('#element_8').val();
r5 = $('#element_9').val();
r6 = $('#element_10').val();
r7 = $('#element_11').val();
r8 = $('#element_12').val();
e1 = $('#element_18').val();
e2 = $('#element_19').val();
e3 = $('#element_20').val();
e4 = $('#element_21').val();
e5 = $('#element_22').val();
e6 = $('#element_23').val();
e7 = $('#element_24').val();
e8 = $('#element_25').val();
b1 = $('#element_34').val();
b2 = $('#element_37').val();
b3 = $('#element_41').val();
b4 = $('#element_44').val();
b5 = $('#element_47').val();
b6 = $('#element_50').val();
b7 = $('#element_53').val();
s1 = $('#element_63').val();
s2 = $('#element_68').val();
s3 = $('#element_71').val();
s4 = $('#element_74').val();
s5 = $('#element_77').val();
s6 = $('#element_80').val();
s7 = $('#element_89').val();
s8 = $('#element_90').val();
s9 = $('#element_91').val();
s10 = $('#element_92').val();
s11 = $('#element_95').val();
s12 = $('#element_98').val();
s13 = $('#element_101').val();
s14 = $('#element_104').val();
s15 = $('#element_107').val();
s16 = $('#element_110').val();
s17 = $('#element_113').val();
s18 = $('#element_116').val();
s19 = $('#element_119').val();
s20 = $('#element_122').val();
c1 = $('#element_16').val();
//This is where we assign a variable (an element) and also we calculate what that variable should be from above.
tr = parseInput(r1) + parseInput(r2) + parseInput(r3) + parseInput(r4) + parseInput (r5) + parseInput (r6) + parseInput (r7) + parseInput (r8);
$('#element_14').val(parseInput(mt).toFixed(2));
ttp = parseInput(s1) + parseInput(s2) + parseInput(s3) + parseInput(s4) + parseInput (s5) + parseInput (s6) + parseInput (s7) + parseInput (s8) + parseInput(s9) + parseInput(s10) + parseInput(s11) + parseInput(s12) + parseInput (s13) + parseInput (s14) + parseInput (s15) + parseInput (s16) + parseInput(s17) + parseInput (s18) + parseInput (s19) + parseInput (s20) ;
$('#element_125').val(parseInput(mt).toFixed(2));
te = parseInput(e1) + parseInput(e2) + parseInput(e3) + parseInput(e4) + parseInput (e5) + parseInput (e6) + parseInput (e7) + parseInput (e8);
$('#element_57').val(parseInput(mt).toFixed(2));
ts = parseInput(b1) + parseInput(b2) + parseInput(b3) + parseInput(b4) + parseInput(b5) + parseInput(b6) + parseInput(b7);
$('#element_64').val(parseInput(yt).toFixed(2));
// Calculate Income - Expenses
ttpi = parseInput(ttp) + parseInput(ts);
$('#element_31').val(parseInput(EM).toFixed(2));
tpc = parseInput(ttp) ;
$('#element_17').val(parseInput(EM).toFixed(2));
cd = parseInput(tr) + parseInput(tpc);
$('#element_31').val(parseInput(EM).toFixed(2)); //This is where you calculate fields that have totals to come up with a grand total.
});
}
});
// Default values to 2 decimal points
function parseInput(val) {
val = parseFloat(val, 10);
if(isNaN(val)) {
return 0;
} else {
return val;
}
}