A
Anz
Is there any javascript function for counting the number of lines
inside a text area ?
inside a text area ?
Is there any javascript function for counting the number of lines
inside a text area ?
RoLo said:try:
a.value.split("\n").length
Anz said:Is there any javascript function for counting the number of lines
inside a text area ?
As for actual lines, independent of presentation:
textarea.value.split(/\r?\n|\r/).length
Is there any javascript function for counting the number of lines
inside a text area ?
In comp.lang.javascript message
In addition to what others have written, ISTM that there is a question
of whether blank lines within, before, or after non-blank lines should
be counted.
Evertjan. said:<textarea id=t>
qqq
sss
www
</textarea>
<script type='text/javascript'>
var r;
var t = document.getElementById('t');
r = t.value.split(/\n/).length;
alert(r); // 9
r = t.value.split(/\n*/).length;
alert(r); // 18
r = t.value.split(/[\r\n]+/).length;
alert(r); // 3
r = t.value.split(/\n[\r\n]*/).length;
alert(r); //4
</script>
==================================
18 ???
What is happening here [IE7]?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.