Can't set the width of a textbox

Can't set the width of a textbox

I have code that makes a textbox dynamically.  I want to set the width with an argument.  It may work the first time, but not the second or third.  I'm using plain javascript, but maybe jquery could solve it.   Here is the code:
  1.  // +++++++++++++
  2.     function createTextBox(maxlength, theid) {
  3.         var newTextBox = document.createElement('input');
  4.         newTextBox.type = 'text';
  5.         newTextBox.setAttribute('id', theid);
  6.         newTextBox.setAttribute('maxlength', maxlength);
  7.         var width = maxlength;
  8.         if (width > 80) {
  9.             width = 80;
  10.             }
  11.         newTextBox.setAttribute('width', width + 'em');
  12.         var newDiv = document.getElementById("newDiv");
  13.         newDiv.appendChild(newTextBox);
  14.         maxx = width + 20;
  15.         }