Posted By

erraja_07 on 05/06/11


Tagged

text limit


Versions (?)

Jquery Limit Text in Textarea


 / Published in: jQuery
 

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

  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. }

Report this snippet  

You need to login to post a comment.