title: creating multiple functions in for loop
body: <p>I am attempting to create a number of functions within a for loop. I think I have the variables all correct - I'm just struggling with the function. It is always calling the function with the last variables input in (it is just trying to add 2 numbers and output the result to the correct div - num1 + input1 = total1, num2 + input2 = total2 etc - outputting into the last div currently) - I think this is because I haven't numbered the function and I am unsure of the syntax to do so - however I may be completely off the point as well...</p>
  
  <pre><code>&lt;div id="num1"&gt;11&lt;/div&gt;
  
  &lt;input type=number value=2 id="input1"&gt;
  
  &lt;div id="total1"&gt;0&lt;/div&gt;
  
  &lt;div id="num2"&gt;11&lt;/div&gt;
  
  &lt;input type=number value=2 id="input2"&gt;
  
  &lt;div id="total2"&gt;0&lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  
  for(var x=1; x&lt;3; x++){
  
  var num = "num"+x;
  var input = "input"+x;
  var total = "total"+x;
  var element = "element"+x;
  var inputelement = "inputelement"+x;
  var thesum = "thesum"+x;
  
  element = document.getElementById(num),
  inputelement = document.getElementById(input),
  thesum = document.getElementById(total);
  document.getElementById(input).onchange = function() {
  thesum.innerHTML = parseInt(element.innerHTML) + parseInt(inputelement.value);
  };
  };
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Many thanks in advance for any help or advice.</p>