Count lines in textarea


/ Published in: JavaScript
Save to your folder(s)



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

URL: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21378738.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.