Copy link to clipboard
Copied
Hi! I am looking for code that I can put in the "Custom Calculation Script" section of the Text Field Properties in Acrobat Pro DC.
Part of the form I am creating has six fields:
String 1 - No.
String 2 - No.
String 3 - No.
Total Strings
String 4 - No.
String 5 - No.
String 6 - No.
Total Strings
I need to know how many fields get used, not the sum total of what's in the fields. For instance, if the user types:
String 1 - No. = 8
String 2 - No. = 10
String 3 - No.
String 4 - No. = 12
String 5 - No.
String 6 - No.
I need to know how many the first three strings are used (2) and how many from the second three strings are used (1).
String 1 - No. = 8
String 2 - No. = 10
String 3 - No.
Total Strings = 2
String 4 - No. = 12
String 5 - No.
String 6 - No.
Total Strings = 1
You can use something like this for the first group, as the custom calculation script of the total field:
var count = 0;
for (var i=1; i<=3; i++) {
var v = this.getField("String "+i+" - No.").valueAsString;
if (v!="") count++;
}
event.value = count;
And then just change the starting and ending numbers in the loop for the second group.
Copy link to clipboard
Copied
Do you already have a code that you've worked on and can share here ?
This may be possible using an array method to count how many text fields are not empty (or null, or blank if you prefer).
Copy link to clipboard
Copied
I have pretty much no code experience. I just read through and try to guess what it means and fiddle with it until I get what I want. So, I was just using code I found in other parts of the community, but I couldn't get anything to work.
Copy link to clipboard
Copied
You can use something like this for the first group, as the custom calculation script of the total field:
var count = 0;
for (var i=1; i<=3; i++) {
var v = this.getField("String "+i+" - No.").valueAsString;
if (v!="") count++;
}
event.value = count;
And then just change the starting and ending numbers in the loop for the second group.
Copy link to clipboard
Copied
Awesome! That worked perfectly. Thank you so much. 🙂