I have an essay question that requires 100 words or more. I can get it to count correctly IF the student does not use separate paragraphs. The input onChange passes the value as the variable words.
The problem: If there are separate paragraphs the count is off by one for each of the paragraphs. My code:
var countWords=0;
function numWords(words){
//the replace deletes any double spaces that most typists use to separate sentences. Double spaces create two commas when the split occurs.
words=words.replace(". ", ". "
;
var ttcnt=words.split(" "
;
countWords=ttcnt.length;
}
The input:
<TEXTAREA Rows="10" Cols="65" name="16" id="Q16" onchange="numWords(this.value)">Introduction.</TEXTAREA>
The problem: If there are separate paragraphs the count is off by one for each of the paragraphs. My code:
var countWords=0;
function numWords(words){
//the replace deletes any double spaces that most typists use to separate sentences. Double spaces create two commas when the split occurs.
words=words.replace(". ", ". "
var ttcnt=words.split(" "
countWords=ttcnt.length;
}
The input:
<TEXTAREA Rows="10" Cols="65" name="16" id="Q16" onchange="numWords(this.value)">Introduction.</TEXTAREA>