Results 1 to 3 of 3

Thread: Javascript that calculates % of another calculation

  1. #1
    Join Date
    Apr 2014
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Javascript that calculates % of another calculation

    I have code which calculates 8% of the number entered, so for example is in the code below. If you enter "1" in the first box" and "100" in the second box the Total Refund (including 8%) = 108

    JavaScript code:
    Code:
    $(document).ready(function() {
        var sum = 0;
        function calcSum(prevVal) {
            var val1 = $('#val1').val();
            var val2 = $('#val2').val();
            var val3 = $('#val3').val();
            var val4 = $('#val4').val();
            this.sum = parseFloat(val1) * parseFloat(val2) + parseFloat(val3) * parseFloat(val4);
            return this.sum;
        }
        var subAmt = $("#sub"),
            taxAmt = $("#tax"),
            totAmt = $("#total");
        $(".val").each(function() {
            var prevVal = this.value / 1,
                self = this;
            $(this).keyup(function() {
                subAmt.val(calcSum.call(self, prevVal));
                totAmt.val(this.sum + this.sum * parseFloat(taxAmt.val() / 100));
                prevVal = self.value; 
            });
        });
    });

    http://jsfiddle.net/2k1zr59u/3/

    What I would like to do is to calculate 20% of the 8% in the second to the bottom box. So in this example the answer should be 1.60.

    Then I would like to show in the total box 106.40 (108 - 1.60).
    Last edited by Beverleyh; 06-11-2015 at 04:25 PM. Reason: Formatting

  2. #2
    Join Date
    Apr 2014
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Can anyone help me please?

  3. #3
    Join Date
    Apr 2014
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    I received some help and have it working now, thanks

Similar Threads

  1. calculation problem with javascript
    By swazisteve in forum JavaScript
    Replies: 0
    Last Post: 02-10-2014, 08:16 AM
  2. Javascript Calculation help!
    By NewbieScott in forum JavaScript
    Replies: 2
    Last Post: 03-02-2011, 05:32 PM
  3. calculation with javascript
    By Piotto in forum JavaScript
    Replies: 6
    Last Post: 11-08-2009, 05:51 PM
  4. Calculation using javascript
    By balaji bala in forum JavaScript
    Replies: 2
    Last Post: 11-26-2008, 02:03 PM
  5. JavaScript Calculation Help?
    By jonsey in forum JavaScript
    Replies: 6
    Last Post: 02-07-2007, 02:08 PM

Tags for this Thread

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
  •