PDA

View Full Version : Max number of words in textareas



Macca
04-20-2010, 10:26 AM
Hi all. I hope someone can help me.

I have a script that counts the number of characters and an alert when the total excedes the limit. What I want is to change this to words rather than characters.

current code:
[CODE]
function maxLength(field,maxWords)
{
if(field.value.length >= maxWords) {
event.returnValue=false;
alert("more than " +maxWords + " words");
return false;
}

}

function maxLengthPaste(field,maxWords)
{
event.returnValue=false;
if((field.value.length + window.clipboardData.getData("Text").length) > maxWords) {
alert("more than " +maxWords + " ");
return false;
}
event.returnValue=true;
}

[CODE]

I then add [ICODE] onKeyPress='return maxLength(this,"500");' onpaste='return maxLengthPaste(this,"500");' [ICODE] within the textarea.

Grafeful if anyone has something similar for words.

thanks

Macca
05-05-2010, 08:51 AM
Does anyone have anything slightly similar to my code above for word count?