Skip to main content
Nikolaos.
Inspiring
February 12, 2020
Answered

Only count text fields with content

  • February 12, 2020
  • 1 reply
  • 4260 views

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 has been closed for replies.
Correct answer Thom Parker

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++; 

 

1 reply

John T Smith
Community Expert
February 12, 2020

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

Nikolaos.
Nikolaos.Author
Inspiring
February 12, 2020

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.

Nikolaos.
Nikolaos.Author
Inspiring
February 12, 2020

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.