title: How to auto sum dynamic input fields in javascript
body: <p>I'm trying to make an auto sum.</p>
  
  <p>I'm starting with a text input field and a button. Pushing the button ads a new input field. Sum field should get ... the sum.
  I have troubles adding the values in javascipt.</p>
  
  <p>Thanks!</p>
  
  <pre><code>var counter = 1;
  sum.value= number0.value;
  function addNumber(divName){          
        var newdiv = document.createElement('div');
        newdiv.innerHTML = "&lt;input type='text' name='number" + counter + "'&gt;";
        document.getElementById(divName).appendChild(newdiv);
        sum.value += document.getElementById("number' + counter + '").value;
        nr++;          
   }
  
  ...
  
  &lt;div id="field"&gt; Add value: &lt;input type="button" value="add" onClick="addNumber('total');"&gt;&lt;br&gt;
  &lt;div id="total"&gt;&lt;input type="text" name="number0"&gt;&lt;/div&gt;
  
  &lt;input type="text" name="sum" id="sum"&gt;
  </code></pre>