I've done a bit of searching on this. Found plenty of scripts that counted characters and even counted words but couldn't find one that removes any words that go over the word limit....
Here is my script so far...:
var maxWords = 10;
function countWordsLeft(field) {
totalWords = field.value.split(' ');
if (totalWords.length > maxWords)
field.value = field.value.substring(0, maxWords);
else
document.getElementById('description_count').innerHTML = maxWords - totalWords.length;
}
I've got the following line which I copied from a character count script but obviously this wont work because I am counting words
if (totalWords.length > maxWords)
field.value = field.value.substring(0, maxWords);
How do I make the script delete any extra words added over the limit? I need this especially if they paste in a description... It needs to count the words and then delete any words over the limit.
Appreciate your help!