Expand my Community achievements bar.

SOLVED

Is it possible to count words in a field

Avatar

Former Community Member

Is it possible to count words in a field, and have the results of that count show up in another field in LiveCycle? Such as the following regular html Javascript Code: If so, what is the correct syntax for the two different boxes??? Thanks! Daria

1 Accepted Solution

Avatar

Correct answer by
Level 6

Check out the attached example.  It uses regular expressions, so some caveats:

1. My regex skills stink, so it may not count words as perfectly as you like.  It's pretty tolerant of special characters but a string like "this & that" will count as 3 words, since the & is counted as a word.  You can tweak the regular expression to adjust to your needs.

2. Since this uses javascript regular expressions, it will work fine in Reader and Acrobat but I don't think it will work for forms rendered on the Livecycle server (such as in Output).  For some reason regex support is missing in the Livecycle server javascript engine; or if it is there it doesn't work on my server.

The script is in the exit: event of the data entry text box.  You can type in (or paste) text into that text box and when you tab out of the box the word count will update.  You can move the script into a different event on your form depending on when you need the words counted.

Let me know how this works out for you.

View solution in original post

3 Replies

Avatar

Level 10

I think the only way would be to have a function that split the value of the field based on spaces.

Jasmin

Avatar

Correct answer by
Level 6

Check out the attached example.  It uses regular expressions, so some caveats:

1. My regex skills stink, so it may not count words as perfectly as you like.  It's pretty tolerant of special characters but a string like "this & that" will count as 3 words, since the & is counted as a word.  You can tweak the regular expression to adjust to your needs.

2. Since this uses javascript regular expressions, it will work fine in Reader and Acrobat but I don't think it will work for forms rendered on the Livecycle server (such as in Output).  For some reason regex support is missing in the Livecycle server javascript engine; or if it is there it doesn't work on my server.

The script is in the exit: event of the data entry text box.  You can type in (or paste) text into that text box and when you tab out of the box the word count will update.  You can move the script into a different event on your form depending on when you need the words counted.

Let me know how this works out for you.

Avatar

Former Community Member

Keven,

Thanks, this works great in LiveCycle, at least so far. I really appreciate it.

Daria