Created
September 25, 2012 15:08
-
-
Save daveespionage/3782495 to your computer and use it in GitHub Desktop.
Super simple Character Limit checker in Javascript
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
// Check character count and limit input field | |
// ------------------------------------------- | |
// Original from: http://www.9lessons.info/2010/04/live-character-count-meter-with-jquery.html | |
// | |
$("#tweetBox").on('keyup',function() | |
{ | |
var box=$(this).val(); | |
var limit= 140 | |
var count= limit - box.length; | |
if(count >= 0) | |
{ | |
$('#count').html(count); | |
} | |
else | |
{ | |
// truncate | |
$(this).val(box.substring(0,limit)); | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment