title: Calculating Table Row Averages and Totals at the same time
body: <p>I'm trying to work out the Javascript required to calculate an average for a table row on the fly, then also update the total for all the same type of rows. Here's a simplified jsfiddle that illustrates this:</p>
  
  <p><a href="http://jsfiddle.net/fmdataweb/5ZtQZ/3/" rel="nofollow noreferrer">http://jsfiddle.net/fmdataweb/5ZtQZ/3/</a></p>
  
  <p>The user can select any type of fruit from the drop down list then enter the number and weeks. For example if they select "Apple" and enter 5 as the number and 26 for the weeks I would like to automatically then calculate the average, which in this case would be 2.5 (number * weeks / 52).</p>
  
  <p>I would also then like to automatically total the averages for the same type of fruit selection. Currently it is totalling the Number column - I need to change this to the Average column, and have this fire after the average is calculated. So if the user selected Apple in more than one row it would then find all instances of this and total the value in the Average column.</p>
  
  <p>I've got some code from another file that will work out the average but I'm having trouble combining the 2 scripts into 1, or knowing if that is the best option or otherwise how to have 2 separate scripts. Here's some psuedo code I found for calculating the averages:</p>
  
  <pre><code>$("#fruit input").live("keyup", function(){
  var id = this.id.match(/\d+/);
  var number = ( ($("#number"+id).val() * $("#weeks"+id).val()  )/52 );
  var rounded = Math.round( number * 10 ) / 10;
  $("#average"+id).val( rounded );
  </code></pre>
  
  <p>Happy to use ID's if that makes everything easier. Appreciate if anyone can enlighten me as to how to achieve this or if you can point to any examples that do something similar. I'm new to Javascript.</p>