I wish to create a textarea which will extend its height according to how many lines there in it so that one won't need to scroll. To do this I have created a textarea thus:
-
<textarea id="myText" cols=10 rows=1 wrap="hard" style="overflow-y:hidden; width:50%; height:25px;" onKeyUp="wordWrap()"></textarea>
-
Everytime the user type in the textarea it calls the function 'wordWrap()' which detects the number of lines in the textarea and adjusts the height accordingling:
-
var height = 25;
-
function wordWrap()
-
{
-
n = editArea.value.split(/\n/).length;
-
height = n*15;
-
editArea.style.height = (height+10)+'px';
-
window.status = n;
-
}
-
The problem I have is that this function will only calculate the line created by the user pressing ENTER and not lines created by automatic (hard) wrap (which to my knowledge inserts carriage returns automatically where the lines break).
How can I detect all newlines/line breaks/carriage returns in my textarea? Has anyone done something like this before. I've scoured the internet for a solution without luck.
Netvibes.com have manage to get this to work almost perfect. But I've noticed a little glitch when u write a word that is too long.