I have a calculator and using JQuery Calculator plug-in which Tally’s up groups of field values using key up.
I have a summary page which presents the user with over all expenditure
what I need to do is subtract the expenditure from income, populate a total field onclick of an <li>
If you want the calculation to be all done at once, could you use negative numbers for the values that need to be subtracted?
I am using an keyup event to summarise expenditure (this goes into a summary form section)
The summary button scrolls the form to the summary screen and its this button i would like perform the final calculation of expenditure and income
If the calculate plugin won’t be used for the summary, you can do it yourself, with something like this:
var form = document.getElementById('summary'),
income = form.elements.income.value,
expenditure = form.elements.expenditure.value,
total = form.elements.total.value;
total.value = (income - expenditure).toFixed(2);
I did it like this
Not the most elegant im sure you will agree (tips welcome)
$("#summary").click(function(){ // summary is the button name
inc1 = $('#SummaryIncome').val();
exp1 = $('#SummaryHouseholdExpenses').val();
exp2 = $('#SummaryTravelCosts').val();
exp3 = $('#SummaryRegularBills').val();
exp4 = $('#SummaryCar').val();
exp5 = $('#SummaryFinance').val();
exp6 = $('#SummaryHealth').val();
exp7 = $('#SummaryLeisure').val();
outTots = parseFloat(exp1)+
parseFloat(exp2)+
parseFloat(exp3)+
parseFloat(exp4)+
parseFloat(exp5)+
parseFloat(exp6)+
parseFloat(exp7);
inTots = parseFloat(inc1);
totals = inTots - outTots;
$('#total').val(totals);
});