• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

New Here ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

51

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

LATEST

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.

 

calculate.jpg

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines