tags:

views:

31

answers:

2

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

+2  A: 
textBox.value.split("\n").length
Matthew Flaschen
please clear that what is textBox here?is it id of text box or...
picnic4u
No, it's the DOM element. You can get it with `getElementById`.
Matthew Flaschen
This will only work for <ENTER>. If the text auto-wraps this will not work!
aSeptik
if the text auto wrap then how this work?
picnic4u
It will return the number of hard lines (from enter).
Matthew Flaschen
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
If the last line of the row is a hard newline, it will double count it.
Matthew Flaschen