Text Box Character Limiter Counter

Create textbox textarea counter limitter using javascript.

1. Type this script and insert between head tag

<script language='javascript'>
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;}
</script>

2. Usage :

<form name="form1" method="post" action="">
<textarea name="txthead"
onKeyDown="textCounter(this.form.txthead,this.form.commentlen,200);"
onKeyUp="textCounter(this.form.txthead,this.form.commentlen,200);">
Type Here..</textarea>
<br>
<input readonly type=text name=commentlen size=3 maxlength=3 value="200">
</form>

Example :





Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.