Posted By

skrippendorf on 06/10/09


Tagged

javascript js textmate jquery text char limit


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


limitChars


 / Published in: jQuery
 

Textauszählen mit jQuery einfach gemacht ;)

  1. $('#message').keyup(function(){
  2. limitChars('message', 160, 'charlimitinfo');
  3. });
  4.  
  5.  
  6. // The Function
  7.  
  8. function limitChars(textid, limit, infodiv)
  9. {
  10. var text = $('#'+textid).val();
  11. var textlength = text.length;
  12. if(textlength > limit)
  13. {
  14. $('#' + infodiv).html('You cannot write more then '+limit+' characters!');
  15. $('#'+textid).val(text.substr(0,limit));
  16. return false;
  17. }
  18. else
  19. {
  20. $('#' + infodiv).html(''+ (limit - textlength) +'');
  21. return true;
  22. }
  23. }

Report this snippet  

You need to login to post a comment.