title: How can I add multiple numbers in JavaScript?
body: <p>I'm new to JavaScript Programming.. I've been researching for the solution but still.. no luck. E.g: I want to add like 6 numbers (or more) that the user will input. I use this code but only the first three are calculated. When I add like four numbers already, 'NAN' appears. Nan means invalid computation.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function show() {
   var a = document.calc.B1.value*1; 
   var b = document.calc.B5.value*1;
   var c = document.calc.B9.value*1;
   var d = document.calc.B12.value*1;
   var e = document.calc.B17.value*1;
   var f = document.calc.B21.value*1;
  
   document.calc.t1.value = a + b + c + d + e + f;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Only B1, B5 and B9 are calculated. Here's the working code:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function show() {
   var a = document.calc.B1.value*1; 
   var b = document.calc.B5.value*1;
   var c = document.calc.B9.value*1;
   document.calc.t1.value = a + b + c;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Here's the form action:</p>
  
  <pre><code>&lt;form action="sysdocadd.php" method="post" name="calc"&gt;
  t1= TOTAL (text type
  &lt;td&gt;&lt;div align="center" class="style66"&gt;&lt;input name="t1" type="text" size="18" id="t1" value="0.00"/&gt;&lt;/div&gt;&lt;/td&gt;
  </code></pre>
  
  <p>When I click calculate button, the result will be shown on t1 text area. here's the code for that..</p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;&lt;span class="style77"&gt;Click to add&lt;/span&gt;&lt;/td&gt;
  &lt;td&gt;&lt;div align="center" class="style66"&gt;&lt;input type=button onClick='show()'value=Calculate /&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>Please help me. :(</p>
  
  <hr>
  
  <p>Here's the sysdocadd.php code:</p>
  
  <pre><code>&lt;?php
  $con = mysql_connect("localhost","user","password");
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  
  mysql_select_db("dbconnect", $con);
  
  $sql="INSERT INTO contents (reportnum, postedby, sysdate, userdateinp, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12,
                              B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, B30,
                              B31, B32, B33, B34, B35, B36, B37, B38, B39, B40, B41, B42, B43, B44, B45, B46, B47, B48, B49, B50, B51, B52,
                              B53, B54, B55, B56, t1, t2, t3, t4)
                              VALUES
  ('$_POST[reportnum]','$_POST[postedby]','$_POST[sysdate]','$_POST[userdateinp]','$_POST[B1]','$_POST[B2]','$_POST[B3]',
  '$_POST[B4]','$_POST[B5]','$_POST[B6]','$_POST[B7]','$_POST[B8]','$_POST[B9]','$_POST[B10]','$_POST[B11]','$_POST[B12]',
  '$_POST[B13]','$_POST[B14]','$_POST[B15]','$_POST[B16]','$_POST[B17]','$_POST[B18]','$_POST[B19]','$_POST[B20]','$_POST[B21]',
  '$_POST[B22]','$_POST[B23]','$_POST[B24]','$_POST[B25]','$_POST[B26]','$_POST[B27]','$_POST[B28]','$_POST[B29]','$_POST[B30]',
  '$_POST[B31]','$_POST[B32]','$_POST[B33]','$_POST[B34]','$_POST[B35]','$_POST[B36]','$_POST[B37]','$_POST[B38]','$_POST[B39]','$_POST[B40]',
  '$_POST[B41]','$_POST[B42]','$_POST[B43]','$_POST[B44]','$_POST[B45]','$_POST[B46]','$_POST[B47]','$_POST[B48]','$_POST[B49]','$_POST[B50]',
  '$_POST[B51]','$_POST[B52]','$_POST[B53]','$_POST[B54]','$_POST[B55]','$_POST[B56]','$_POST[t1]','$_POST[t2]','$_POST[t3]','$_POST[t4]')";
  
  if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
  echo "1 record added";
  
  mysql_close($con)
  ?&gt; 
  </code></pre>