/    Sign up×
Community /Pin to ProfileBookmark

Works in FF3 and IE7, but not IE6

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;
}[/CODE]

I call it in the webpage with this snippet:

[code=html]
“onKeyUp”=”countWords(document.getElementById(‘textAreaEntry’),document.getElementById(‘curWordCount’))”
[/code]

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. ?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @sysbuilder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...