Created
November 18, 2013 18:22
-
-
Save brunopulis/7532731 to your computer and use it in GitHub Desktop.
Textarea counter
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
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