title: adding an uncertain number of fields using javascript
body: <p>I'm new to javascript and a novice programmer, so this might be a really easy question to answer. I would like to loop over the values of x number of fields and add them up to display the sum in a final field. I can perform this function if I explicitly call each field, but I want to abstract this so I can deal with a flexible number of fields. Here's example code I've come up with (that's not working for me). Where am I going wrong?</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  function startAdd(){
      interval = setInterval("addfields()",1);
  }
  function addfields(){
      a = document.addition.total.value;
      b = getElementByTagName("sum").value;
      for (i=0; i&lt;=b.length; i++){
          a+=i;
      }
      return a;
  }
  function stopAdd(){
      clearInterval(interval);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form name="addition"&gt;
  
   &lt;input type="text" name="sum" onFocus="startAdd();" onBlur="stopAdd;"&gt;
  + &lt;input type="text" name="sum" onFocus="startAdd();" onBlur="stopAdd;"&gt;
  = &lt;input type="text" name ="total"&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>