Created
May 28, 2010 08:54
-
-
Save joecritch/416923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Limit character lengths on textareas using jQuery and metadata | |
// //////////////////////////// | |
// Store the metadata in data() for quicker access on the event. | |
var textboxesToLimit = $('textarea.character_limit'); | |
textboxesToLimit.each(function() { | |
$(this).data('maxlength', $(this).metadata().maxlength); | |
}).keyup(function() { | |
var len = this.value.length; | |
var maxlength = $(this).data('maxlength'); | |
if (len >= 150) { | |
this.value = this.value.substring(0, maxlength); | |
} | |
$(this).nextAll('.charsLeft').text(maxlength - len); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment