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

Only count text fields with content

Contributor ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

Hello everyone,

would like to count only text fields with content.

Examble: I have twenty (20) text fields and I would like in the twentyone (21) text field that it only adds up the fields that have content. If there are only 6 text fields with content, then the number six should appear.

 

I probably need JavaScript. Any help is welcome.

 

Thx in Advance,

 

Nikolaos.

Views

2.8K

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

correct answers 1 Correct answer

Community Expert , Feb 13, 2020 Feb 13, 2020

This "if" condition will test for blank input

 

if (f.valueAsString=="") count++; 

 

 This one will test non-spaces, 

if (!/^\s*$/.test(f.valueAsString)) count++; 

 

Votes

Translate

Translate
Community Expert ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

Please post the name of the Adobe program you use so a Moderator may move this message to that forum

Votes

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
Contributor ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

Sorry you're right, of course.

In the heat of the moment, I quickly forget.

It's about Adobe Acrobat Pro DC (2015).

 

In the meantime, let my brain run a bit (as far as possible, since I'm at the very beginning with javascript),

I have the following approach:

var fields = ["C10", "C20", "C30", "C40", "C50", "C60", "C70", "C80", "C90", "C100", "C110", "C120", "C130", "C140", "C150", "C160", "C170", "C180", "C190", "C200"]; 

    var count = 0; 

    for (var i=0; i<fields.length; i++) { 

        var f = this.getField(fields[i]); 

        if (f.valueAsString=="X") count++; 

    } 

    event.value = count; 

 

Please have a look and tell me or better show me a other solution/approach 🙂

 

Thank you for your patience and time in advance 🙂

 

Nikolaos.

Votes

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
Contributor ,
Feb 12, 2020 Feb 12, 2020

Copy link to clipboard

Copied

The problem in this solution is that it always has to be an X to count (or any else text).

How do I get it to work so that no matter what text or value is written in the text field ?,..and count immediately.

Votes

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 13, 2020 Feb 13, 2020

Copy link to clipboard

Copied

This "if" condition will test for blank input

 

if (f.valueAsString=="") count++; 

 

 This one will test non-spaces, 

if (!/^\s*$/.test(f.valueAsString)) count++; 

 

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

Votes

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
Contributor ,
Feb 13, 2020 Feb 13, 2020

Copy link to clipboard

Copied

Hi Thom_Parker,

 

thx for your quick response and help 🙂

 

Need a little more help, I'm just a newbie with javascripting :-).
Would like to count other text fields.
Have 17 text fields, the 18 text field should count all text fields that are empty (of the 17)  and the total of empty fields appears in the 18 text field.

What should the Javascript look like? ... and where should it be installed?

If you would help me there, it would be a huge help for me
....sayed probably all desperate like me here 🙂
 
Thx,
 
Nikolaos.

 

Votes

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 13, 2020 Feb 13, 2020

Copy link to clipboard

Copied

The script you already posted is perfect. Where is this script installed? It should be a calculation script on the 18th field. 

I just provided suggestions for changing out the "if" for counting blanks. 

 

 

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

Votes

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
Contributor ,
Feb 14, 2020 Feb 14, 2020

Copy link to clipboard

Copied

LATEST

Now I understand it 🙂

 

Sometimes it takes a bit longer until I have understood 🙂

 

Big Thx, was really a big help.

 

Nikolaos.

Votes

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