Here's a script that dynamically keeps track of how many words have been entered. The script changes any new line characters into single spaces and then splits the string into separate pieces wherever there is a space. All of the pieces that actually contain something are "words" and get counted.
function cnt(w,x){
var y=w.value;
var r = 0;
a=y.replace(/\s/g,' ');
a=a.split(' ');
for (z=0; z
x.value=r;
}
Call this routine whenever your visitor tries to enter anything into either field (we include the count field so that anything they enter there will be changed back into the correct count of words in the field we are counting). We do this by using the onkeyup method so that the count is recalculated every time anything is typed.
Source: Unknown
Viewed 7293 times