title: Calculate % from number generated
body: <p>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</p>
  
  <p>JavaScript code:</p>
  
  <pre><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; 
          });
      });
  });
  </code></pre>
  
  <p><a href="https://jsfiddle.net/2k1zr59u/3/" rel="nofollow">JSFiddle</a>.</p>
  
  <p>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. </p>
  
  <p>Then I would like to show in the total box 106.40 (108 - 1.60).</p>