Disclaimer: I’ve fairly new to Javascript.
I wrote a piece of word counting code (basically ported it over from a PHP implementation) that updates a certain span on the page with current word count in a textarea.
[CODE]function countWords(targetString,targetField) {
targetString=targetString.value;
var words=0;
var wordQualifyRegex=/[0-9A-Za-zÀ-ÖØ-öø-ÿ]/;
// replace all extra spaces with single spaces
var textRegex=/ +/;
var text=targetString;
var text=targetString.replace(textRegex,” “);
var textWords=text.split(” “);
for (i=0;i<textWords.length;i++) {
if(wordQualifyRegex.test(textWords[i])) {
words++;
}
}
// alert(words);
targetField.innerHTML=words;
}
I call it in the webpage with this snippet:
[code=html]
“onKeyUp”=”countWords(document.getElementById(‘textAreaEntry’),document.getElementById(‘curWordCount’))”
where textAreaEntry is the id of the textarea and curWordCount is the id of the span I want to update with the current word count.
This code works perfectly in both FF3 and IE7, but in IE6, the word count doesn’t update.
Any insight into why the code might break in IE6 would be much appreciated. ?