- Code: Select all
textAreaMin = 3;
function sizeTextAreaHeight(obj)
{
var text = obj.value.replace(/\s+$/g,"")
var split = text.split("\n")
var count = split.length;
if(count > textAreaMin)
{
obj.rows = count + 1;
}
}
function sizeTextAreaWidth(obj)
{
var parent = obj.parentNode;
var width = (parent.offsetWidth == 0)?parent.clientWidth:parent.offsetWidth;
obj.cols = Math.floor(0.123 * width);
}
Since figuring out how many columns and rows to use can be difficult, since its not in px, i've created some functions to help.
The sizeTextAreaHeight determines the number of rows to use based upon the content inside of it
And the sizeTextAreaWidth determines the number of columns based upon the width of the parent object that it is in. For example, if the parent object is a div with a width of 200px, the textarea will become roughly 200px wide.


