cplus_man
asked on
Get number of lines in a text area
Is there any direct way to find out (using JavaScript) how many lines of user-entered text there are in a multi-line text area on an HTML form?
ASKER
Is there also a way to count lines where the text was automatically wrapped? My textarea's wrap attribute is set to 'physical', and I'm using IE 6.
assuming no \n characters:
var lines = Math.round( document.nameOfYourForm.na meOfYourTe xtarea.val ue.length / (1*document.nameOfYourForm .nameOfYou rTextarea. cols) );
var lines = Math.round( document.nameOfYourForm.na
ASKER
I guess IE 6 does not insert \n characters at wrapping points no matter what the wrap attribute is set to. Is that true? I have tried using both 'hard' and 'physical' for the wrap attribute on my textarea and IE still never seems to put the \n's at the wrapping points. That issue has been bugging me because it would be very helpful in solving this problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, I have combined both of the above approaches. It works, but it's not 100% accurate. But I guess it's the best I'll be able to do. Thanks for your help.
var lines = document.nameOfYourForm.na
alert(lines);