Question : get textarea line count.. full and correct line count.. in FF to IE to safari

Hello, I need to get the line count of a textarea.. works great in FF but not in IE.. this is what I have..


function countlines(area) {
            var text = area.val();
            var lines = text.split(/\r\n|\r|\n/);
            return (lines.length);
      }
countlines($('#SIA')) ;

which works fine in FF ..  In IE it gets close but seems to mis some.. So I try with out anyluck to add crlf cr lf to the mix...

Any one know how to fix it?  Cheers -Jeremy




Answer : get textarea line count.. full and correct line count.. in FF to IE to safari

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
<html>
<head>
<script>
function countLines(theArea){
  var theLines = theArea.value.replace((new RegExp(".{"+theArea.cols+"}","g")),"\n").split("\n");
  if(theLines[theLines.length-1]=="") theLines.length--;
  theArea.form.lineCount.value = theLines.length;
}
</script>
</head>
<body>
<form>
<textarea name="myText" onKeyUp="countLines(this)" cols="10" rows="10">
</textarea>
<br>
Lines:
<input type=text name="lineCount" size="2" value="0">
</form>
</body>
</html>
Random Solutions  
 
programming4us programming4us