function limitChars(textarea, limit){
  var text = $(textarea).val();
  var length = text.length;
  if(length > limit){
    $(textarea).val(text.substr(0, limit));
    return false;
  } else {
    return true;
  }
}

$(document).ready(function(){
  $('textarea').each(function(){
    if(this.attributes.maxlength){
      $(this).keydown(function(){
        limitChars(this, this.attributes.maxlength.value)
      })
    }
  })
})