Textarea counter with javascript

Hello friends. Here is a simple script to count characters of a textarea.

The Javascript

<script type="text/javascript">
function counter(txtfield,countfield,maxlimit) {
    if (txtfield.value.length > maxlimit)
        txtfield.value=txtfield.value.substring(0,maxlimit);
    else
        countfield.value = maxlimit - txtfield.value.length;
    }
</script>


The Html Form
 
<form name="counterForm">
  <textarea name="msg" onKeyUp="counter(this,charLeft,50)">
  </textarea>
  Characters Left =
  <input readonly="readonly" type="text" name="charLeft"
  size="4" maxlength="4" value="50" style="border:0" >
</form>


The Example
 


Characters Left =
Textarea counter with javascript Textarea counter with javascript Reviewed by JS Pixels on August 20, 2011 Rating: 5

No comments:

Altaf Web. Powered by Blogger.