SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    If you want the calculation to be all done at once, could you use negative numbers for the values that need to be subtracted?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    If the calculate plugin won't be used for the summary, you can do it yourself, with something like this:

    Code javascript:
    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);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did it like this

    Not the most elegant im sure you will agree (tips welcome)
    Code:
    $("#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);
    
    	});


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •