Jquery Limit Text in Textarea


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



Copy this code and paste it in your HTML
  1. $(document).ready(function(){
  2. $(function(){
  3. $('#bid_desc-plaintext').keyup(function(){
  4. limitChars('bid_desc-plaintext', 4000, 'typed_txt_count');
  5. })
  6. });
  7. });
  8.  
  9. function limitChars(textid, limit, infodiv)
  10. {
  11. var text = $('#'+textid).val();
  12. var textlength = text.length;
  13. if(textlength > limit)
  14. {
  15. $('#' + infodiv).html('You cannot write more then '+limit+' characters!');
  16. $('#'+textid).val(text.substr(0,limit));
  17. return false;
  18. }
  19. else
  20. {
  21. $('#' + infodiv).html((limit - textlength) +' characters left.');
  22. return true;
  23. }
  24. }

URL: http://www.ajaxray.com/blog/2007/11/09/interactive-character-limit-for-textarea-using-jquery/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.