title: How to sum values stored in an array of textboxes
body: <p>How to sum the values stored in an array of textbox using <strong>javascript</strong> and display it in a separate <code>&lt;div id="hasil"&gt;&lt;/div&gt;</code>.</p>
  
  <p>Thank you all.</p>
  
  <p>This is my javascript:  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function tambah() {
      var sum = 0;
      var cost = document.getElementsByName('jumlah[]');
      for (var i = 0; i &lt; cost.length; i++)
      {
          sum += parseFloat(cost[i].value);
      }
      document.getElementById('hasil').value = sum;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
      &lt;body&gt;
          &lt;form id="hitung" name="hitung"&gt;
              &lt;label&gt;Jumlah&lt;/label&gt; &lt;br&gt; 
              &lt;span class="input-group-addon"&gt;Rp.&lt;/span&gt;
              &lt;input name="jumlah[]" type="text" class="form-control" onChange="tambah();" &gt;
              &lt;span class="input-group-addon"&gt;,00&lt;/span&gt;&lt;br&gt;
              &lt;span class="input-group-addon"&gt;Rp.&lt;/span&gt;
              &lt;input name="jumlah[]" type="text" class="form-control" onChange="tambah();" &gt;
              &lt;span class="input-group-addon"&gt;,00&lt;/span&gt;&lt;br&gt;
              &lt;span class="input-group-addon"&gt;Rp.&lt;/span&gt;
              &lt;input name="jumlah[]" type="text" class="form-control" onChange="tambah();" &gt;
              &lt;span class="input-group-addon"&gt;,00&lt;/span&gt;
              &lt;div id="hasil"&gt;&lt;/div&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>