Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Created November 20, 2012 15:00
Show Gist options
  • Save tcelestino/4118430 to your computer and use it in GitHub Desktop.
Save tcelestino/4118430 to your computer and use it in GitHub Desktop.
counter limit textarea
// limitador de caracteres
var limitText = function() {
var count = 600; // value limit caracter
var txt = document.forms[0].text.value;
var len = txt.length;
var countText = document.getElementById("your-counter"); // create element your html
if(len > count){
txt = txt.substring(0,count);
document.forms[0].text.value = txt;
return false;
}
countText.innerHTML = count-len;
}
// use jquery or other
$("textarea").keyup(function(){
limitText();
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment