Is there a way to count the words entered into a text entry field?

Feb 06, 2013

I am creating a writing exercise in Storyline in which the user has to edit a paragraph that is 130 words down to 53 words.

I would like to be able to calculate  the number of words the user ended up using and display it back to them.

Any ideas on how I could do this?  the course has to run on html5 so a flash solution is not viable.

14 Replies
Steve Gannon

The 'control' in this case is the text entry box. When the user clicks outside of the box or clicks on a button or whatever, the control loses focus. You typically use this condition with a text entry box; you can assume the user is done typing when the control has lost focus because the cursor is no longer in the text entry box. Hope that clarifies...

Rebecca Fleisch Cordeiro

Wow, Steve! This is so very cool!

And I have a question. It seems contractions are counted as two words. Since I know nothing about javascript, except that I'm good at C/P it - how could your script be edited to accommodate contractions?

I see that there's stuff in there for white space and non-alphanumeric characters, but I have no idea what to do with it.

Thanks, Nancy for the question and Steve for the response. This one's a keeper in what's becoming my ever-growing resource list!

Rebecca Fleisch Cordeiro

Hi Nancy,

I understand that contractions replace two (or more) words and arguably could be defined as such. Interestingly, some dictionaries define this as "a word" formed by leaving letters out of two (or more) words; others are less clear, simply saying a shortening of a word or words.

Microsoft Word, THE authority on all things grammatical counts them as one word.

I guess it depends on what the client wants. I did a quick search (VERY quick) and found that writing contests with word count limitations consider them to be one word.