title: how to add n number of input value with javascript
body: <p>Friends, I want the sum of the numbers I put in fields and these input value total are equal to my total value. it show a Nan Error When i add these input values please help</p>
  
  <blockquote>
    <p>This is my body Content</p>
  </blockquote>
  
  <pre><code>    &lt;form action="" method="post"&gt;
      &lt;input type="text" name="cnum" placeholder="enter no. of input"&gt;
      &lt;input type="submit" name="submit" &gt;
      &lt;/form&gt;
      &lt;?php
      if(isset($_POST['cnum']))
      {
          $cnum=$_POST['cnum'];
          $i=0;
          ?&gt;
      &lt;form action="" method="post"&gt;
          &lt;input type="hidden" name="total" id="total" value="10"&gt;
          &lt;input type="hidden" name="cnum" id="cnum" value="&lt;?php echo $cnum ;?&gt;"&gt;
          &lt;?php
          while($i&lt;$cnum)
          {
              ?&gt;
                  &lt;input type="number" id="aq&lt;?php echo $i; ?&gt;" onKeyup="add()" name="aq&lt;?php echo $i; ?&gt;"&gt;&lt;br /&gt;
              &lt;?php
              $i++;
          }
      ?&gt;
          &lt;input type="submit" name="aqsub"&gt;
      &lt;/form&gt;
      &lt;?php
      }
      ?&gt;
  </code></pre>
  
  <blockquote>
    <p>This is my java script function</p>
  </blockquote>
  
  <pre><code>var val=0;
  var total=document.getElementById('total').value;
  var cnum=document.getElementById('cnum').value;
  var anum;
  function add()
  {
  var n=0;
  while(n&lt;cnum)
  {
      anum = 0;
      if(document.getElementById('aq'+n).value != "")        {            
              anum=parseInt(document.getElementById('aq'+n).value);
          }
      val += anum;
      n++;
  }
  alert(val);
  
  }
  </code></pre>