This javascript function will help you to limit/count the size of characters entered/typed in text area or in text box.
Features
a)You can limit the number of characters to be entered/typed in text area/textbox.
b)This javascript displays number of characters left to type in textbox.
c)Easy to specify the size/length of character counter/limiter.
d)Just copy the code in to your page and use it.
e)Simple and ease of use.
Preview for Character Counter
Code
Javascript Code
<!-- Script by hscripts.com -->
<script type="text/javascript">
//Edit the counter/limiter value as your wish
var count = "125"; //Example: var count = "175";
function limiter(){
var tex = document.myform.comment.value;
var len = tex.length;
if(len > count){
tex = tex.substring(0,count);
document.myform.comment.value =tex;
return false;
}
document.myform.limit.value = count-len;
}
</script>
<!-- Script by hscripts.com -->
For customization of this script or any script development, contact us at support@hscripts.com
Usage
Here we have explained, how to use the count character javascript with the help of a form. The count value decreases when you type each character into textbox.
Copy the javascript code into the head part of your HTML page.
Copy the HTML code, This will create a textarea to enter the words/characters,Also a form field will be created which counts the character.
<form name="myform" METHOD=POST>
<textarea name=comment wrap=physical rows=3 cols=40 onkeyup=limiter()></textarea><br>
<script type="text/javascript">
document.write("<input type=text name=limit size=4 readonly value="+count+">");
</script></form>
d)You can easily set the limit or counter as your wish. If you wish to restrict the user not to type more than 250 characters in text area/textbox change the count value as 250. This will set the length or size of text area or text box.
Example:var count = "250";
The java script function "limiter()" will limit the size or length of characters typed in textarea or text box.
License
- The javascript (misspelled as java script) is given under GPL License
- i.e. Free use for those who use the codes as it is.
- Free, if your modification does not remove our copyright information and links.
- Click Here for detailed license information.
- You can purchase the script if your requirements does not meet our GPL License terms.