var display = $('ACT1_wordCountDisplay');
var questionID = this.questionId;
var textbox =$('QR~' + questionID);
var that = this;
function countWords(s){
s = s.replace(/\\n/g,' '); // newlines to space
s = s.replace(/(^\\s*)|(\\s*$)/gi,''); // remove spaces from start + end
s = s.replace(/[ ]{2,}/gi,' '); // 2 or more spaces to 1
if(s == ''){
return 0;
}else{
return s.split(' ').length;
}
}
textbox.onkeyup = function(e){
display.update(countWords(textbox.value));
console.log(textbox.value);
}
Best answer by fleb
View original