title: Javascript function not working
body: <p>Im trying to use the below function to find values in form fields, The reason its loops is because the form changes dynamically which means there could be gaps in the ID of the field</p>
  
  <p>Java script function is</p>
  
  <pre><code>function totalProductPrice() {
          var maxid = document.getElementById("field_id").value;
          var i = 0;
          var totalprice = 0;
  
          while (i&lt;=maxid)
              {
                  totalprice += document.getElementById("QuoteItem" + i + "price").value;
                  i++;
              }
  
          document.getElementById("QuoteTotalcost").value = totalprice;
      }
  </code></pre>
  
  <p>and then on one of the input fields i have</p>
  
  <pre><code>onchange='totalProductPrice();'
  </code></pre>
  
  <p>When i change the value of this field it should add up all the fields and then insert it into the field called QUoteTotalcost but when i try it does nothing, In the console of firebug it outputs</p>
  
  <pre><code>element.dispatchEvent is not a function
  [Break on this error] element.dispatchEvent(event);
  prototype.js (line 4619)
  document.getElementById("QuoteItem" + i + "price") is null
  [Break on this error] totalprice += document.getElementById("QuoteItem" + i + "price").value; 
  </code></pre>