Question
word count of a textarea
I want to calculate the word count of a textarea and display the value in the text "textcount".
The following code work for Firefox 3.6.9 & Chrome 6.0 & IE 7.
However, the initial word count for an empty textarea is 1 for IE 7.
OS is Windows XP Pro SP3.
How to code which will work for all browsers?
var countField = eval("fieldObj.form."+"textcount");
var wordcount = fieldObj.value.split(/\s+/g).length;
if (wordcount > 0)
if (navigator.appName != 'Microsoft Internet Explorer')
wordcount = wordcount - 1;
countField.value = wordcount;