title: How do I sum sub-totals fields to calculate grand total?
body: <p>I have a form for the item, quantity, price fields which user dynamically adds or deletes. Now I want to add sub totals and the grand totals to the form.</p>
  
  <p>Until now, I have been able to use the following code, but this just subtotals for the first row and not for the rest of the rows, and also grand total is also required.</p>
  
  <p>Javascript: </p>
  
  <pre><code>function totalprice()
  {
      a = document.form1.quantity.value
      b = document.form1.price.value
  
      c = a * b
  
      document.form1.total.value = c
  } 
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form action="here.php" method="post" name="form1"&gt;
      Quantity: &lt;input name="quantity" size="10"&gt;Price: &lt;input name="price" size="10" onblur="totalprice();"&gt;&lt;br&gt;
      Total: &lt;input name="total" size="10" readonly=true&gt;&lt;br&gt;
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>