Textarea limitazione caratteri


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



Copy this code and paste it in your HTML
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title>Limit Number of Characters in a TextArea</title>
  7. <script type='text/javascript'
  8. src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'></script>
  9. <script type='text/javascript'>
  10. $(document).ready(function() {
  11. $('#note').keyup(function() {
  12. var max=140;
  13. var len = this.value.length;
  14. if (len >= max) {
  15. this.value = this.value.substring(0, max);
  16. }
  17. $('#charLeft').text(max - len);
  18. });
  19. });
  20. </script>
  21. </head>
  22. <body>
  23. <textarea id="note" cols="20" rows="8"></textarea><br/>
  24. (Maximum characters: 140)<br/>
  25. <span id="charLeft"> </span> Characters left
  26. </body>
  27. </html>
  28.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.