Created
November 20, 2012 15:00
-
-
Save tcelestino/4118430 to your computer and use it in GitHub Desktop.
counter limit textarea
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
// 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