Skip to main content
Nikolaos.
Inspiring
Feb 12, 2020 6:49 PM UTC
Answered

Only count text fields with content

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.

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Feb 13, 2020 8:35 PM UTC

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.


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

7 replies

John T Smith
Community Expert
Community Expert
Feb 12, 2020 6:52 PM UTC

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

Translate
Nikolaos.
Nikolaos.Author
Inspiring
Feb 12, 2020 7:08 PM UTC

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.

Translate
Nikolaos.
Nikolaos.Author
Inspiring
Feb 12, 2020 7:11 PM UTC

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.

Translate