title: Sum numbers of each line with js
body: <p>What I need is when I enter numbers to textarea, I need it to get the sum of each line. </p>
  
  <p>Example of entered lines on Textarea:</p>
  
  <ol>
  <li>10 10 10</li>
  <li>99 11</li>
  <li>11 11</li>
  </ol>
  
  <p>Example of Div where I get sum of each line</p>
  
  <ol>
  <li>30</li>
  <li>110</li>
  <li>22</li>
  </ol>
  
  <p>I have a script, but it shows results only with alerts. I don't know how to do it, so it would show all results on div. Now div shows only the results of last line.</p>
  
  <pre><code>$('#sub').click(function() {
  
     var grandTotal = 0,
         rowTotals = [], // array to hold individual row totals
         rowData,
         rows,
         val,
         rawData = document.getElementById('nums').value;
  
     // if desired replace this comment with regex validation of rawData
  
     rows = rawData.split("\n");
  
     for (var i=0; i &lt; rows.length; i++) {
        rowTotals[i] = 0;
        rowData = rows[i].split(" ");
        // if you need to test that each row has the same number
        // of values in it do that here
  
        for (var j=0; j &lt; rowData.length; j++) {
           val = parseFloat(rowData[j]);
           // add validation of val here
           rowTotals[i] += val;
        }
  
        alert("Total for row " + (i + 1) + ": " + rowTotals[i]);
          // ALERT SHOWS RESULT FOR EVERY LINE
  
  $('#res').html(rowTotals[i]);
          // HTML SHOWS RES FOR LAST LINE ONLY. I NEED IT TO SHOW RESULTS OF ALL LINES
     }
  });
  </code></pre>
  
  <p>&nbsp;</p>
  
  <pre><code>&lt;textarea id="nums" rows="10"&gt;&lt;/textarea&gt; 
      &lt;div id="res"&gt;&lt;/div&gt;
  &lt;input type="button" id="sub" value="Sum"&gt;
  </code></pre>
  
  <p><a href="https://jsfiddle.net/9yc70csj/1/" rel="nofollow">https://jsfiddle.net/9yc70csj/1/</a></p>