title: Calculate the Price automatically in invoice
body: <p>I am making an invoice system, I want to get the price textbox to be automatically calculated. I am having a table of random rows, in the invoice. How do I do it via a JS function on price text box.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var rowCount = 0;
  
  function addRow(tableID) {
  
    var table = document.getElementById(tableID);
  
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
  
    var cell1 = row.insertCell(0);
    var element1 = document.createElement("input");
    element1.type = "checkbox";
    element1.name = "chk[]";
    cell1.appendChild(element1);
  
    var cell2 = row.insertCell(1);
    cell2.innerHTML = rowCount;
  
    var cell3 = row.insertCell(2);
    var element2 = document.createElement("input");
    element2.type = "text";
    element2.name = "item[]";
    element2.required = "required";
    cell3.appendChild(element2);
  
    var cell4 = row.insertCell(3);
    var element3 = document.createElement("input");
    element3.type = "text";
    element3.name = "qty[]";
    cell4.appendChild(element3);
  
    var cell5 = row.insertCell(4);
    var element4 = document.createElement("input");
    element4.type = "text";
    element4.name = "cost[]";
    cell5.appendChild(element4);
  
    var cell5 = row.insertCell(4);
    var element4 = document.createElement("input");
    element4.type = "text";
    element4.name = "price[]";
    cell5.appendChild(element4);
  
  
  
  }
  
  function deleteRow(tableID) {
    try {
      var table = document.getElementById(tableID);
      var rowCount = table.rows.length;
  
      for (var i = 0; i &lt; rowCount; i++) {
        var row = table.rows[i];
        var chkbox = row.cells[0].childNodes[0];
        if (null != chkbox &amp;&amp; true == chkbox.checked) {
          table.deleteRow(i);
          rowCount--;
          i--;
        }
  
  
      }
    } catch (e) {
      alert(e);
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /&gt;
  
  &lt;INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /&gt;
  &lt;form action="" method="post" enctype="multipart/form-data"&gt;
    invoice:
    &lt;INPUT type="text" name="invoice id" /&gt;
  
    &lt;TABLE id="dataTable" width="350px" border="1" style="border-collapse:collapse;"&gt;
      &lt;TR&gt;
        &lt;TH&gt;Select&lt;/TH&gt;
        &lt;TH&gt;Sr. No.&lt;/TH&gt;
        &lt;TH&gt;Item&lt;/TH&gt;
        &lt;TH&gt;Cost&lt;/TH&gt;
        &lt;TH&gt;Qty&lt;/TH&gt;
        &lt;TH formula="cost*qty" summary="sum"&gt;Price&lt;/TH&gt;
      &lt;/TR&gt;
      &lt;TR&gt;
        &lt;TD&gt;
          &lt;INPUT type="checkbox" name="chk[]" /&gt;
        &lt;/TD&gt;
        &lt;TD&gt; 1 &lt;/TD&gt;
        &lt;TD&gt;
          &lt;INPUT type="text" name="item[] " /&gt; &lt;/TD&gt;
        &lt;TD&gt;
          &lt;INPUT type="text" name="qty[]" /&gt; &lt;/TD&gt;
        &lt;TD&gt;
          &lt;INPUT type="text" name="cost[]" /&gt; &lt;/TD&gt;
        &lt;TD&gt;
          &lt;INPUT type="text" name="price[]" /&gt; &lt;/TD&gt;
      &lt;/TR&gt;
  
    &lt;/TABLE&gt;
    &lt;input type="submit" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>