title: calculate grand total with javascript
body: <p>I don't know how to get Grand total value</p>
  
  <p>grand total is sum of all total</p>
  
  <p>here is the code</p>
  
  <pre><code>&lt;?php
  $con = mysqli_connect('localhost', 'root', '', 'a.karat');
  if(isset($_POST['product_id']))
  {
  $prno=$_POST['prno'];
  $i=1;
  $sql = mysqli_query($con,"select * from detail_pr where prNo='$prno'");
  while ($r = mysqli_fetch_array($sql)) {
  
      echo 
  
      '&lt;tr&gt;
   &lt;td&gt;&lt;input type="checkbox" name="check[]" id="check'.$i.'"    value="'.$i.'"&gt;&lt;/td&gt;
   &lt;td&gt;&lt;label for="productCode"&gt;&lt;/label&gt;
    &lt;input type="text" name="productCode'.$i.'" id="productCode'.$i.'" readonly value="'.$r["productCode"].'" size="12" &gt;&lt;/td&gt;
  &lt;td&gt;&lt;label for="productName"&gt;&lt;/label&gt;
    &lt;input type="text" name="productName'.$i.'" id="productName'.$i.'" readonly value="'.$r["productName"].'"size="35" &gt;&lt;/td&gt;
  &lt;td&gt;&lt;label for="qty"&gt;&lt;/label&gt;
    &lt;input type="number" onkeyup="calc(this);" name="qty'.$i.'" id="qty'.$i.'" readonly value="'.$r["qty"].'" size="8" &gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="number" onkeyup="calc(this);" name="price'.$i.'" id="price'.$i.'" size="10" min="1" max="99" onchange="calc(this);" &gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="number" onkeyup="calc(this);" name="discount'.$i.'" id="discount'.$i.'" size="10" min="0" max="99" onchange="calc(this);"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="number" name="total'.$i.'" id="total'.$i.'" size="10" min="1" max="99" onchange="calc(this);" &gt;&lt;/td&gt;
    &lt;/tr&gt;';
    $i++;
      }
  }
  ?&gt;
  
  
  &lt;table width="400" border="0" align="right"&gt;
      &lt;tr&gt;
      &lt;th scope="row"&gt;Grand Total&lt;/th&gt;
       &lt;td&gt;:&lt;/td&gt;
      &lt;td&gt;&lt;input name="grandtotal" id="grandtotal" type="text"&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;script&gt;
       function calc(id) {
    var row = id.parentNode.parentNode;
    var quant = row.cells[3].getElementsByTagName('input')[0].value;
    var price = row.cells[4].getElementsByTagName('input')[0].value;
    var disc = row.cells[5].getElementsByTagName('input')[0].value;
    if (disc == null || disc == '') {
      res = parseFloat(quant) * parseFloat(price);
    } else {
      var res = (parseFloat(quant) * parseFloat(price)) - (parseFloat(quant) *     parseFloat(price) * (parseFloat(disc) / 100));
    }
    row.cells[6].getElementsByTagName('input')[0].value = res;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I have manage to calculate total per row </p>
  
  <p>now I need your help to sum all total and put the value in the grandtotal textbox</p>