[JS]Expand Rows in Textbox

I don’t really need crit (and im sure there are better ways to code this… probably could think of a few ways), I just found out a better way to do what I wanted to do and don’t need my form to autoexpand.

(btw this implies the font in the textbox is courier (the 8 pixels thick thingy).


var intTemp;
function autoexpand(){
    if (intTemp != document.form.textboxname.value.length){
        intTemp = document.form.textboxname.value.length
        var strTemp = "";
        var strLineCounter = 0;
        var strCharCounter = 0;
        for (var i = 0; i < document.form.textboxname.value.length; i++)
        {
            var strChar = document.form.textboxname.value.substring(i, i + 1);
            if (strChar == '
')
            {
                strTemp += strChar;
                strCharCounter = 1;
                strLineCounter += 1;
            }
            else if (strCharCounter ==  Math.floor(document.form.textboxname.clientWidth/8))
            {
                strTemp += '
' + strChar;
                strCharCounter = 1;
                strLineCounter += 1;
            }
            else
            {
                strTemp += strChar;
                strCharCounter ++;
            }
        }
        if(strLineCounter < 5){
            document.form.textboxname.rows = 5;
        }
        else
        {
            document.form.textboxname.rows = strLineCounter+1;
        }
        clearInterval(id);
    }
}
id = setInterval('autoexpand()', 100);

//edit, although if you do spend the time to make it better/redo please feel free to paste the source.