example: <textarea id=”id” maxlength=”255″></textarea>
jQuery(‘textarea[maxlength]‘).keyup(function() {
var max = parseInt(jQuery(this).attr(‘maxlength’));
if (jQuery(this).val().length > max) {
jQuery(this).val(jQuery(this).val().substr(0, jQuery(this).attr(‘maxlength’)));
}
if (jQuery(this).parent().find(‘.charsRemaining’).length > 0) jQuery(this).parent().find(‘.charsRemaining’).html(‘You have ‘ + (max – jQuery(this).val().length) + ‘ characters remaining’);
else jQuery(this).parent().append(‘<div class=”charsRemaining”>You have ‘ + (max – jQuery(this).val().length) + ‘ characters remaining</div>’);
});