how can i get the no. of rows in the multilines textbox through javascript function if some body inserted many no of text in that textbox
please clear that what is textBox here?is it id of text box or...
picnic4u
2010-06-03 09:57:41
No, it's the DOM element. You can get it with `getElementById`.
Matthew Flaschen
2010-06-03 09:58:24
This will only work for <ENTER>. If the text auto-wraps this will not work!
aSeptik
2010-06-03 09:59:55
if the text auto wrap then how this work?
picnic4u
2010-06-03 10:03:44
It will return the number of hard lines (from enter).
Matthew Flaschen
2010-06-03 10:08:18
A:
UPDATED:
DEMO: http://jsbin.com/uqavo3/2
var nums_of_rows = countLines( 'textarea_id');
function countLines(areaId){
var theArea = document.getElementById(areaId);
var theLines = theArea.value.replace((new RegExp(".{"+theArea.cols+"}","g")),"\n").split("\n");
if(theLines[theLines.length-1]=="")
theLines.length--;
return theLines.length;
}
<textarea cols="#" rows="#" id="">some text here</textarea>
aSeptik
2010-06-03 10:22:49
If the last line of the row is a hard newline, it will double count it.
Matthew Flaschen
2010-06-04 11:37:28