title: jQuery with table how to calculate the sum of user's entered values?
body: <p>I have a jquery problem, I am fetching results in an array from my sql database.
  The items are in a <code>table tr td</code>. Each row holds a unique id.</p>
  
  <p>but when i do the sum or doing onkeyup for one text box the all total change also.</p>
  
  <p>I am uding an <code>onKeyUp</code> event for <code>Qty</code>. </p>
  
  <p>eg.: </p>
  
  <blockquote>
    <p>Qty = 3</p>
    
    <p>Bedrag = 20</p>
    
    <p>Totaal (expected) = 60</p>
  </blockquote>
  
  <p>Here is a screenshot:
  <img src="https://i.stack.imgur.com/TNfDQ.png" alt="enter image description here"></p>
  
  <p>Is my jQuery code wrong?</p>
  
  <pre><code>jQuery(document).ready(function(){
  
      var j = 0;
      /* COMPUTATION new item */
      jQuery('input[id=new_quan_'+j+']').keyup(function(){
          j++;
          var new_sum = parseInt($('input[id=new_quan_'+j+']').val(), 10);
          new_sum *= parseInt($('input[id=new_amt_'+j+']').val(), 10);
          jQuery('input[id=new_total_'+j+']').val(new_sum);
      });
  }); 
  </code></pre>
  
  <p>Here is the HTML and PHP code:</p>
  
  <pre><code>&lt;table cellpadding="5" cellspacing="0" width="100%" id="computation_table"&gt;
      &lt;tbody&gt;
      &lt;tr&gt;
          &lt;th&gt;Categories&lt;/th&gt;
          &lt;th&gt;Qty&lt;/th&gt;
          &lt;th&gt;Omschrijving&lt;/th&gt;
          &lt;th&gt;Bedrag&lt;/th&gt;
          &lt;th&gt;Totaal&lt;/th&gt;
          &lt;th&gt;BTW&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;?
      $quo_com = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE user_code = '".$_GET['uc']."' and footnote = 'new' and active='1' " ) or die ( mysql_error() );
      $get_btw = mysql_fetch_array( $quo_com );
      if ( $get_btw['currency'] == 'euro' ) {
          $msg_tot = '&amp;euro;';
      } elseif ( $get_btw['currency'] == 'usd' ) {
          $msg_tot = '&amp;#36;';
      }
  
      $sqlview = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE user_code = '".$_GET['uc']."' and footnote = 'new' and active='1' " ) or die ( mysql_error() );
      $j = 0;
      while( $row = mysql_fetch_array( $sqlview ) ) {
      ?&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type="hidden" name="id_&lt;?=$j?&gt;" value="&lt;?=$row['q_id'];?&gt;" /&gt;
              &lt;input type="hidden" name="counter" value="&lt;?=$j?&gt;" /&gt;
              &lt;input type="text" name="category_&lt;?=$j?&gt;" class="text_com" value="&lt;?=$row['category'];?&gt;" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="text" name="quantity_&lt;?=$j?&gt;" id="new_quan_&lt;?=$j?&gt;" class="text_com" value="&lt;?=$row['quo_quantity'];?&gt;" /&gt; x
          &lt;/td&gt;
          &lt;td width="200"&gt;
              &lt;input type="text" name="quo_definition_&lt;?=$j?&gt;" class="input" value="&lt;?=$row['quo_definition'];?&gt;" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="text" name="quo_amt_&lt;?=$j?&gt;" id="new_amt_&lt;?=$j?&gt;" class="text_com" value="&lt;?=$row['quo_amt'];?&gt;" /&gt;
          &lt;/td&gt;
          &lt;td id="total"&gt;
              &lt;input type="text" name="quo_total_&lt;?=$j?&gt;" id="new_total_&lt;?=$j?&gt;" class="text_com" value="&lt;?=$row['quo_total'];?&gt;" /&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="text" name="quo_btw_&lt;?=$j?&gt;" class="text_com" value="&lt;?=$row['quo_btw'];?&gt;" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;?
      $j++;
      }
  ?&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;br /&gt;
  &lt;!-- END OF COMPUTATION UPDATE --&gt;
  &lt;input type="submit" name="up_item_list" value="Werk de vorm" /&gt; - &lt;input type="submit" name="new_save_list" value="Opslaan nieuw item" /&gt; - &lt;a href=""&gt;Annuleren&lt;/a&gt;
  &lt;/form&gt;
  </code></pre>