<input id="txt" type="text" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';">