Copy link to clipboard
Copied
I am creating a PDF form that has 25 drop-down lists consisting of the following identical options, including:
On another part of the form, I have the same items listed with a text field beside it in a recap section at the end of the form:
Lead ______ GRR ________ NL ________ UNK ________
My goal is that each time a selection is made from one of the lists, the total number of times that selection is made (from all the lists combined) will be displayed in the corresponding recap section.
For example:
If ‘GRR’ is selected total of 8 different times in 8 of the 25 dropdown lists, it will read "8" in the recap section next to the GRR heading.
I am brand new to this – no JavaScript experience at all – so please spell it out for me, and if it would be possible for me to copy and paste the script, that would be AWESOME!
Copy link to clipboard
Copied
Then use this:
var L = 0, GRR = 0, NL = 0, UNK = 0;
for(var i=1; i<=25; i++){
var fieldName = "Material-Category-" + (i < 10 ? "0" + i : i);
if(this.getField(fieldName).valueAsString == "L - Lead")L++;
if(this.getField(fieldName).valueAsString == "GRR - Galvanized Requiring Replacement")GRR++;
if(this.getField(fieldName).valueAsString == "NL - Non-Lead")NL++;
if(this.getField(fieldName).valueAsString == "UNK - Unknown")UNK++;}
this.getField("L-total").value = L;
this.getField("GRR-total").value = GRR;
this.getField("NL-total").value = NL;
this.getField("UNK-total").value = UNK;
Copy link to clipboard
Copied
What are the name of the fields?
Are the values just 'L', 'GRR'...etc or 'L - Lead', 'GRR - Galvanized Requiring Replacement'...etc?
Copy link to clipboard
Copied
The receiving fields are L-total, GRR-total, NL-total, and UNK-total
Thanks!
Copy link to clipboard
Copied
Ok, assuming dropdown fields are named "Dropdown1-25" use this in one of the fields as custom calculation script:
var L = 0, GRR = 0, NL = 0, UNK = 0;
for(var i=1; i<=25; i++){
if(this.getField("Dropdown"+i).valueAsString == "L - Lead")L++;
if(this.getField("Dropdown"+i).valueAsString == "GRR - Galvanized Requiring Replacement")GRR++;
if(this.getField("Dropdown"+i).valueAsString == "NL - Non-Lead")NL++;
if(this.getField("Dropdown"+i).valueAsString == "UNK - Unknown")UNK++;}
this.getField("L-total").value = L;
this.getField("GRR-total").value = GRR;
this.getField("NL-total").value = NL;
this.getField("UNK-total").value = UNK;
Copy link to clipboard
Copied
Thank you. I think I follow... Please forgive my uncertainty; if you could confirm:
The code you provided should be copied into the Custom Calculation Script field of the fields where the totals should appear. So, for the first field - L-total - I should use this piece of script:
var L = 0, GRR = 0, NL = 0, UNK = 0; for(var i=1; i<=25; i++){ if(this.getField("Dropdown"+i).valueAsString == "L - Lead")L++; if(this.getField("Dropdown"+i).valueAsString == "GRR - Galvanized Requiring Replacement")GRR++; if(this.getField("Dropdown"+i).valueAsString == "NL - Non-Lead")NL++; if(this.getField("Dropdown"+i).valueAsString == "UNK - Unknown")UNK++;} this.getField("L-total").value = L;
In the code, for each instance of "Dropdown", do I need to have a line for each dropdown list, identifying each one (i.e., Material-Category-01, Material-Category-02, etc.)? Sorry if I'm being dumb or making it more complicated than it is.
Copy link to clipboard
Copied
Not in every field, it is enough if you use script in only one field.
It is important to name fields correctly, and since you named dropdowns 01,02...etc at number 10 and above are you naming your fields 10, 11, 12 or 010, 011, 012?
Copy link to clipboard
Copied
Thank you!
The dropdown list names all have two-digits: Material-Category-01 thru Material-Category-25
Copy link to clipboard
Copied
Then use this:
var L = 0, GRR = 0, NL = 0, UNK = 0;
for(var i=1; i<=25; i++){
var fieldName = "Material-Category-" + (i < 10 ? "0" + i : i);
if(this.getField(fieldName).valueAsString == "L - Lead")L++;
if(this.getField(fieldName).valueAsString == "GRR - Galvanized Requiring Replacement")GRR++;
if(this.getField(fieldName).valueAsString == "NL - Non-Lead")NL++;
if(this.getField(fieldName).valueAsString == "UNK - Unknown")UNK++;}
this.getField("L-total").value = L;
this.getField("GRR-total").value = GRR;
this.getField("NL-total").value = NL;
this.getField("UNK-total").value = UNK;
Copy link to clipboard
Copied
This is perfect and worked like a charm. Thank you so much for all your help!!