title: Javascript 'this' as parameter
body: <p>I'm trying to copy the value from "FROM" fields into "TO" fields. My first attempt was this:</p>
  
  <pre><code>function updateToField(toField,fromField)
  {
      toField.value = fromField.value}
  }
  
  function verifyFromToFields()
  {
  var inputs = getElementsByTagName("input");
  for (var j = 0; j &lt; inputs.length; j++)
  {
      if (inputs[j].name.indexOf('FROM') != -1 &amp;&amp; if (inputs[j+1].name.indexOf('TO') != -1)
          {
              var fromField = inputs[j];
              var toField   = inputs[j+1];
              fromField.onchange = function(){updateToField(toField,fromField)};
          }
  }
  </code></pre>
  
  <p>The website has several FROM-TO pairs, and this only seem to work for the last pair in the "inputs" array.</p>
  
  <p>Then I tried  this:</p>
  
  <pre><code>function updateToField(toField,fromField)
  {
      toField.value = fromField.value}
  }
  
  function verifyFromToFields()
  {
  var inputs = getElementsByTagName("input");
  for (var j = 0; j &lt; inputs.length; j++)
  {
      if (inputs[j].name.indexOf('FROM') != -1 &amp;&amp; if (inputs[j+1].name.indexOf('TO') != -1)
          {
              var fromField = inputs[j];
              var toField   = inputs[j+1];
              fromField.onchange = function(){updateToField(toField,this)};
          }
   }
  </code></pre>
  
  <p>With this, when any FROM field in the page is modified, it's copied to the last TO field on the page. I think this is one of those issues I've read about parameters as value or reference, but I can't figure it out. 
  Also this is a VERY simplified version of the code, I actually fill the inputs list with a getElementsByClass function and must search through childnodes.
  Does anyone have a clue on whats going on?</p>