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)
        countfield.value = maxlimit - txtfield.value.length;

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

The Example

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

No comments:

Altaf Web. Powered by Blogger.