+ 13
how to count lines inside the textarea
Sample Code
7 Answers
+ 13
var count = 0;
var a = document.getElementById("text")
for (let i = 0; i < a.value.length; i++) {
if (a[i] == "\n") {
count++;
}
}
console.log(count);
+ 5
assuming there are no text wrapping, count all of newline character in the value of the textarea.
newline character is \n
+ 3
Sali65 that's a simple stuff
Only the method is important đ€
+ 2
Split it at every newline, then count the length of what the split returns.
0
Rei He means how can JS count it
0
I think you have to make your own fxn for it.
Fix the size of text area and once see how many characters lies in one line (say n).
Store the length of string in textarea as textval
Then
Line_no = Math.ceil(textvalue.length/n);
it will give line number in which you are writting
I hope it will work as you want.
0
Divya Mohan definitely possible if the font is monoscript and using ch unit as width
but that's the only case, other than that it wont be as reliable