Skip to main content
New Participant
February 18, 2020
Question

Help with adding the word count for multiple sections on form to one total word count field

  • February 18, 2020
  • 3 replies
  • 423 views

Hello,

I have a form where I have multiple fields (awords, bwords, cwords, dwords, ewords).  I need the word counts from each of the 5 sections to add up into one total word count field.  I don't need to limit the words, I just need the total number of words from each of the sections to add up into the total words field.

 

Since my IT department claims they don't really do javascript, I am on my own. 

 

My team and I spending hours adding up each individual section to get total word count for form submitted to us. Having the word total added up automatically would be a total game changer.  Thanks for any help!

 

Michelle

This topic has been closed for replies.

3 replies

New Participant
February 18, 2020

There's a tab labeled calculation in the field properties where you have an option to calculate the sum of selected fields. Once you follow @Thom_Parker code to get the word count into the awords, bwords ... etc fields, just create a field for example "total-word-counts" and on the properties select the option I mentioned earlier.

 

try67
Community Expert
February 18, 2020

Use the code Thom provided to calcluate the number of words for each field, and then add up those numbers, either directly in your code or by placing them in (hidden) text fields and then adding those up.

Thom Parker
Community Expert
February 18, 2020

The word count is found by splitting the field value on white space. Then the number of elements is the words. 

Here's a script for a single field. You can run it in the Acrobat Console window. 

You can find a tutorial here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

nWrdCnt = this.getField("awords").valueAsString().replace(/(^\s+)|(\s+$)/g,"").split(/\s+/mg).length;

 

This needs to be done for each field.

 

If you need this number inside the form, you can add a "WordCount" field and make the script a calculation.

If you need this number outside the  form, then it should be an automation tool or a Console window script. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often