title: How to calculate subtotal and grand total in javascript?
body: <p><strong>What I need</strong>
  I want to sum all to amount as the images but I can't do it </p>
  
  <p><strong>As below code how can to total all amount after quantity multiple with unitPrice?</strong></p>
  
  <p><strong>Here is Html element</strong></p>
  
  <pre><code>  &lt;html&gt;
      &lt;form&gt;
      &lt;div&gt;
      Quantity:&lt;input type="text" class="qty"&gt; Unit price:&lt;input type="text" class="unit"&gt;
     Amount: &lt;input type='text' class='amount'&gt;
     &lt;/div&gt;
      &lt;div&gt;
      Quantity:&lt;input type="text" class="qty"&gt; Unit price:&lt;input type="text" class="unit"&gt;
     Amount: &lt;input type='text' class='amount'&gt;
     &lt;/div&gt;
      &lt;div&gt;
      Quantity:&lt;input type="text" class="qty"&gt; Unit price:&lt;input type="text" class="unit"&gt;
     Amount: &lt;input type='text' class='amount'&gt;
     &lt;/div&gt;
      &lt;div&gt;
      Quantity:&lt;input type="text" class="qty"&gt; Unit price:&lt;input type="text" class="unit"&gt;
     Amount: &lt;input type='text' class='amount'&gt;
     &lt;/div&gt;
      &lt;div&gt;
      Quantity:&lt;input type="text" class="qty"&gt; Unit price:&lt;input type="text" class="unit"&gt;
     Amount: &lt;input type='text' class='amount'&gt;
     &lt;/div&gt;
      &lt;div&gt;
      Quantity:&lt;input type="text" class="qty"&gt; Unit price:&lt;input type="text" class="unit"&gt;
     Amount: &lt;input type='text' class='amount'&gt;
     &lt;/div&gt;
      Total All:&lt;input type="text" class="result"&gt;
  &lt;/form&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Here is Javascript code</strong>
  This js can only total from unit price with quantity like <strong>amount = quant*unit</strong></p>
  
  <p><strong>And result should be Result = amount+amount1+amount2+amount3+amount4+amount5. But i can't do that</strong> </p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
          $('.qty,.unit').on('change', function(){
  
                  var qty     = parseFloat($('.quant').val() );
                  var unit    = parseFloat( $('.unit_p').val());
  
                  var quant1  = parseFloat($('.quant1').val() );
                  var unit1   = parseFloat( $('.unit1').val());
  
                  var quant2  = parseFloat($('.quant2').val() );
                  var unit2   = parseFloat( $('.unit2').val());
  
                  var quant3  = parseFloat($('.quant3').val() );
                  var unit3   = parseFloat( $('.unit3').val());
  
                  var quant4  = parseFloat($('.quant4').val() );
                  var unit4   = parseFloat( $('.unit4').val());
  
                  var quant5  = parseFloat($('.quant5').val() );
                  var unit5   = parseFloat( $('.unit5').val());
  
                  var amount  = qty * unit; 
                  var amount1 = quant1*unit1;
                  var amount2 = quant2*unit2;
                  var amount3 = quant3*unit3;
                  var amount4 = quant4*unit4;
                  var amount5 = quant5*unit5;
  
                  var result = [];
  
                  if(isNaN(qty) || isNaN(unit)){
                      $('.amount').val('');
                  }else{
                      $('.amount').val(amount); 
                  }if(isNaN(quant1)||isNaN(unit1)){
                      $('.amount1').val('');
                  }else{
                      $('.amount1').val(amount1); 
                  }if(isNaN(quant2) || isNaN(unit2)){
                      $('.amount2').val('');
                  }else{
                      $('.amount2').val(amount2); 
                  }if(isNaN(amount3) || isNaN(amount3)){
                      $('.amount3').val('');
                  }else{
                      $('.amount3').val(amount3);
                  }if(isNaN(quant4) || isNaN(unit4)){
                      $('.amount4').val('');
                  }else{
                      $('.amount4').val(amount4);
                  }if(isNaN(quant5)||isNaN(quant5)){
                      $('.amount5').val('');
                  }else{
                      $('.amount5').val(amount5);
                  } 
          });
  &lt;/script&gt;
  </code></pre>
  
  <p>I can't sum all amount for total</p>
  
  <p>Please help</p>
  
  <p><img src="https://i.stack.imgur.com/8Ngoo.jpg" alt="enter image description here"></p>