title: Dynamically creating a textbox with a Javascript onkeyup event that takes parameters
body: <p>What I have is a single textbox.  If the user hits the maxlength of it, I want to create a new textbox and then change focus to it so they can continue typing.</p>
  <p>To accomplish this, I am trying to dynamically create textboxes that have an <code>onkeyup</code> event tied to them.  To do this I am using <code>document.createElement</code> and the creation of the element works.  The problem is that I can't get the parameters (the id of the current textbox and the id of the one to be created) to pass correctly and they are simply variables.  Before I pass them I can test them and they are fine, but in the method they are null.</p>
  <p>Here is my code:</p>
  <pre><code> &lt;script type=&quot;text/javascript&quot;&gt;
      var i = 2;
      function CreateTextbox() {
    var box = document.getElementById(divCreateTextbox);
          var curr = 'txt' + i;
          var next = 'txt' + (i + 1);
  
          var inp = document.createElement('input')
          inp.type = 'text';
          inp.name = 'textfield';
          inp.maxlength = '10';
          inp.id = curr;
          inp.setAttribute('onkeyup', 'moveOnMax(inp.id, next)');
          inp.onkeyup = function() { moveOnMax(inp.id, next); };
  
          box.appendChild(inp);
          box.innerHTML += &quot;&lt;br /&gt;&quot;;
  
          i++;
  
          return next;
      }
  
      function moveOnMax(field, nextFieldID) {
          if (field.value.length &gt;= field.maxLength) {
              if (document.getElementById(nextFieldID) == null) {
                  var id = CreateTextbox();
  
                  if (document.getElementById(id) != null) {
                      document.getElementById(id).focus();
                  }
                  else
                      alert(&quot;problem...&quot;);
              }
          }
      }
  &lt;/script&gt;
  
     &lt;div id=&quot;divCreateTextbox&quot;&gt;
  </code></pre>
  <p><br /></p>
    
  <p>I am pretty new to Javascript, so if this is completely fubar'd, I apologize.<br />
  Any help is appreciated.</p>