Count those Words Limited

[Total: 0    Average: 0/5]

This will count the number of words in the input textarea.

Head Code:

<SCRIPT>
function wordCounter(_form, _field, maxlimit)
{
  var _string="";
  var _wordCount=0;
  var _obj=eval("_form."+_field);
  var _IsSpace=false;
  var _WasSpace=false;
  for (var _x=0;_x<_obj.value.length;_x++)
  {
    _WasSpace=_IsSpace;
    _IsSpace=(_obj.value.charAt(_x) == " ");
    
    if(_IsSpace && ! _WasSpace)
    {
      _wordCount++;
      if(_wordCount<maxlimit)
        _string+=" ";
    }
    else if(!_IsSpace)
    {
      if(_wordCount<maxlimit)
        _string+=_obj.value.charAt(_x);
    }
  }
  _obj.value=_string;
  _form.wordCount.value=_wordCount;
}
</script>

Body Code:

<FORM NAME=Surv>
Enter 10 words or less:
<textarea
   name="itemname"
   cols="40"
   rows="5"
   onKeyUp="wordCounter(this.form, 'itemname',10);"
></textarea>
<HR>
<input type=text name="wordCount" value="0" readonly>
<HR>
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *