title: I want to calculate total amount when I change quantity
body: <p>I want to get total amount when I change quantity.</p>
  
  <p>This script is not working in while loop: (quantity * amount = total_amount)</p>
  
  <p>How can I solve this issue?  Please help me to solve this issue.</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>function calculateTotal() {
     var totalAmt = document.addem.total.value;
     totalR = eval(totalAmt * document.addem.tb1.value);
    
     document.getElementById('total_amount').innerHTML = totalR;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;Id&lt;/td&gt;
          &lt;td&gt;Product&lt;/td&gt;
          &lt;td&gt;Quantity&lt;/td&gt;
          &lt;td&gt;Total&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;?php
          $sq=mysql_query("select * from cart_sample where email='$ema'");
          while($row = mysql_fetch_array($sq))
          { ?&gt;
              &lt;td&gt;&lt;?php echo $row['id']; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $row['product']; ?&gt;&lt;/td&gt;
  
              &lt;form name="addem"  id="addem" /&gt;
                  &lt;td&gt;&lt;input type="text" name="tb1" onkeyup="calculateTotal()" value="&lt;?php echo $row['quantity']; ?&gt;" /&gt;&lt;/td&gt;
                  &lt;input type="hidden" name="total"  value="&lt;?php echo $row['amount']; ?&gt;" /&gt;
                  &lt;td&gt;&lt;span id="total_amount"&gt;&lt;/span&gt;&lt;/td&gt;
        &lt;?php } ?&gt;        &lt;/tr&gt;
          &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>