Skip to content

Instantly share code, notes, and snippets.

@brunopulis
Created November 18, 2013 18:22
Show Gist options
  • Save brunopulis/7532731 to your computer and use it in GitHub Desktop.
Save brunopulis/7532731 to your computer and use it in GitHub Desktop.
Textarea counter
message.keypress(function(e) {
var fieldValue = $('textarea').val(),
lengthValue = fieldValue.length,
set = 400,
remain = parseInt( set - lengthValue );
$( '#counter > span' ).text( remain );
if ( remain <= 0 && e.which !== 0 && e.charCode !== 0 )
$('textarea').val( ( fieldValue ).substring( 0, lengthValue - 1 ) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment