Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   find textarea number of cols when it is set to 100% (http://www.velocityreviews.com/forums/t878526-find-textarea-number-of-cols-when-it-is-set-to-100-a.html)

arnaud 07-20-2004 04:29 PM

find textarea number of cols when it is set to 100%
 
Hi,
I have an application whose textareas rows automatically resize onFocus
to the number of lines in the textArea.
The cols are set to 100% (in a CSS file) in order to always take the
full browser width

I use textarea.value.split('\n') to find the number of lines.
Some lines are longer than the 100% width and they wrap.
However, wrappeed lines do not contain '\n'. Thus my textarea has less
lines than what is needed to display it without scroll bars.

I don't want to use wrap='hard' as the text shall be stored in the DB in
its original form (even if lines are too long to be displayed without
wrapping).

I would like thus to get the number of cols dynamically
in order to do:
lines=textarea.value.split('\n');
realNumberOfLines=0;
for(i=0; 1<lines.length; i++) {
realNumberOfLines = realNumberOfLines +
Math.ceil(lines[i].length/textarea.cols);
}
return realNumberOfLines;


The problem is that textare.cols returns -1 in mozilla 1.7 and a value
lower than the reality in IE6.

Does anybody have an idea on how to achieve that?

Regards,
Arnaud.



All times are GMT. The time now is 08:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.