Javascript - Count Down Character Limit on Field


SUBMITTED BY: Guest

DATE: July 23, 2013, 6:16 p.m.

FORMAT: JavaScript

SIZE: 719 Bytes

HITS: 1148

  1. <html>
  2. <head>
  3. <title></title>
  4. <script>
  5. var count = 125;
  6. function limiter() {
  7. var tex = document.getElementById("comment").value;
  8. var len = tex.length;
  9. if (len > count) {
  10. tex = tex.substring(0, count);
  11. document.getElementById("comment").value = tex;
  12. return false;
  13. }
  14. document.getElementById("charLeft").innerHTML = count - len;
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <textarea id="comment" onkeyup="limiter()" ></textarea><br>
  20. <span id=charLeft>125</span> charachers left
  21. </body>
  22. </html>

comments powered by Disqus