Display Ads On This Blog

Banner Ads on scriptforphp.blogspot.com
Provides free php script for php developer.
Prix: € 5.00

Saturday, April 11, 2009

maximum word limit for textarea

<textarea rows="8" cols="28" onKeyUp="checkWordLen(this,200);"></textarea>
TOTAL WORDS : <span id="word_counter" style="color:#FF0000;">0/200</span>

function checkWordLen(obj,MaxLen)
{

var len = obj.value.split(/[\s]+/);

counter = len.length-1;

document.getElementById('word_counter').innerHTML = counter+"/"+MaxLen;

if(len.length > MaxLen)
{
objvalue = obj.value.split(/[\s]+/);

var newval = '';

for(var m=0; m<MaxLen; m++)
{
newval+=objvalue[m]+' ';
}

obj.value='';
obj.value=newval;

return false;
}

return true;
}

2 comments:

  1. Thanks Vasim,

    Great work.

    It works perfectly...

    ReplyDelete
  2. Hi Vasim

    Is there a way you can modify this so it will handle multiple text areas with different max word amounts. Can pay for working script.

    Email me: hugsbu@gmail.com

    Many thanks

    H.

    ReplyDelete