How to set width of text input to physical text width

Giganews Newsgroups
Subject: How to set width of text input to physical text width
Posted by:  johkar (nosendju…@link.net)
Date: Mon, 08 Sep 2003

I have a grid.  When the focus is put on a cell an input is created with the
value being the cell's text.  I would like to size the input to the physical
width of the text.  Ideas?

John

function editCell (cell) {

if (document.getElementById) {
    cell.normalize();
    var input = document.createElement('INPUT');
    input.setAttribute('value', cell.firstChild.nodeValue);
    input.setAttribute('size', cell.firstChild.nodeValue.length);  //RATHER
THAN SET THE SIZE, I WOULD PREFER TO SET STYLE WIDTH

    input.onblur = function (evt) { setCell(this.parentNode,this.value); };
    input.onclick = function (evt) {
    evt.cancelBubble = true;
    if (evt.stopPropagation)
      evt.stopPropagation();
    };

    cell.replaceChild(input, cell.firstChild);

    input.focus();
    input.select();
  }

}

Replies