Counting Words
Thursday August 7, 2008
Count words with JavaScript
Have a text area in a form and want to know how many words your visitor enters? This simple JavaScript will keep count for you.
Counting Words
Count words with JavaScript
Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >
Easy ways to connect two computers for networking purposes. More >
©2009 About.com, a part of The New York Times Company.
All rights reserved.
I had to change:
a=y.replace(’\n’,’ ‘);
to:
a=y.replace(/\n/g,’ ‘);
otherwise words separated only by newlines weren’t counted. (firefox v1.5)
I have updated the page to use /\s/g so that it will even allow for multiple spaces or new lines between words without messing up the count.