Skip to content

Instantly share code, notes, and snippets.

@todoubled
Created July 6, 2010 21:06
Show Gist options
  • Save todoubled/465912 to your computer and use it in GitHub Desktop.
Save todoubled/465912 to your computer and use it in GitHub Desktop.
Character Count
$(function() {
$('#post_message').keyup(function() {
var content_length = $(this).val().length;
var remaining = 420 - content_length
$('.counter').html(remaining);
if (remaining < 0) {
$('input[type=submit]').attr("disabled", "disabled");
} else if (remaining < 21 && remaining > 9) {
$('input[type=submit]').removeAttr("disabled");
$('.counter').removeClass('red');
$('.counter').addClass('dark_red');
} else if (remaining <= 9) {
$('input[type=submit]').removeAttr("disabled");
$('.counter').removeClass('dark_red');
$('.counter').addClass('red');
} else {
$('input[type=submit]').removeAttr("disabled");
$('.counter').removeClass('dark_red').removeClass('red');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment