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.
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++;
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
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.
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.
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++;
Copy link to clipboard
Copied
Hi Thom_Parker,
thx for your quick response and help 🙂
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.
Copy link to clipboard
Copied
Now I understand it 🙂
Sometimes it takes a bit longer until I have understood 🙂
Big Thx, was really a big help.
Nikolaos.