Copy link to clipboard
Copied
I have been using checkboxes and summation boxes from these checkboxes, but it's complicated and slowing down my document for several reasons. I would like to try using summations from dropdowns instead.
i.e. if "FOC" is selected in a dropdown, this value (1) is added to a summation box at the end of the document so you can see that 'FOC' was selected 30 times, 'LOC' was selected 12 times, etc.
Is this possible please? I have done a search of the forums as I did think I'd posted this already but can't find it anywhere and the other threads I have found don't answer my query.
Thank you very much!
Copy link to clipboard
Copied
JavaScript must be turned on for scripts to run. Copying fields from one document to another will work as long as it doesn't cause a conflict with existing field names and scripts in the new document.
Copy link to clipboard
Copied
That's good news, as I have tried copying and pasting and it failed - and I read that you can't copy fields between PDF documents!
Would the script you wrote work on a check-box as well, if the check-boxes are named appropriately? The dropdowns haven't gone down well!
Copy link to clipboard
Copied
I copy and paste fields between documents all the time without issue. Yes it will work with check boxes if the export value matches what the script says.
Copy link to clipboard
Copied
Thank you. I would put the course, or at least a link to my website, in my signature of every answer but it is against community guidelines.
Copy link to clipboard
Copied
There must be a reason your form is performing poorly which may not be solved by switching from checkboxes to dropdowns. This article might help you improve the performance. To add up specific selections from the dropdowns you would have to loop through the fields. You should use a numbering system to name them to make this easier. For example, if you create the first dropdown in a series and name it "Dropdown", then in form editing mode, right-click > Create multiple copies, then enter 25 down and 1 across you will end of with 25 fields named "Dropdown.0" through "Dropdown.24". In the summary field for "FOC" enter the following custom calculation script:
var ttl=0;
for(var i=0;i<25;i++)
{
if(this.getField("Dropdown."+i).value=="FOC")
{ttl++}
}
event.value=ttl;
If your fields are not named with a numbering system you would have to create an array of field names and loop through them instead.
Copy link to clipboard
Copied
Thank you for the link. When you say you added the codes to your "import script", is that the script which appears in All Javascript Strings? So you put code 1 at the very beginning of the text in the Javascript Editor window, and codes 2 and 3 at the very end?
Copy link to clipboard
Copied
No. That is referring to importing field values from a text file. Separate issue.
Copy link to clipboard
Copied
Ok thanks, sadly not going to sort my issue then, I think it's just a complex document!
Copy link to clipboard
Copied
I've tried doing that with LOC as an example but nothing appears in the 'total' field...
Copy link to clipboard
Copied
This is what the debugger says:
TypeError: f is null
1282:byteCodeToolException in line 1 of function top_level, script AcroForm:LOC.total:Calculate
TypeError: this.getField(...) is null
1:AcroForm:LOC.total:Calculate
Copy link to clipboard
Copied
That error means one of the fields named in your script does not exist. Please post your script.
Copy link to clipboard
Copied
Sorry I thought I had but got distracted trying to figure out what was wrong with it comparing it to the one you wrote! The dropdown list(s) are called "Chapter".
var ttl=0;
for(var i=0;i<25;i++)
{
if(this.getField("Chapter."+i).value=="LOC")
{ttl++}
}
event.value=ttl;
Copy link to clipboard
Copied
For that script to work you would need 25 dropdowns called "Chapter.0" through "Chapter.24". We are still confused as to what exactly you are trying to calculate from one dropdown named "Chapter" and another named "Licence".
Copy link to clipboard
Copied
Ah OK - I didn't twig that it was dependent on there being 25 fields. I just created four fields initially to see if it works. I've amended the script to be <4; or <1; or <1.1 but to no avail. The fields are called Chapter0.0, Chapter0.1, Chapter1.0 and Chapter1.1 (I created multiple copies as recommended).
I don't really know how to explain it more clearly than in my earlier post. I have to calculate the number of times LOC (for example) is selected under Chapter headings and also I need to calculate the number of times B1 (for example) is selected under a Licence heading.
So ultimately want to show under the heading
B1:
LOC - 7
FOT - 2
SGH - 19
RI - 32
MEL - 7
TS - 12
Total B1 - ...
B2:
LOC - 7
FOT - 2
SGH - 19
RI - 32
MEL - 7
TS - 12
Total B2 - ...
B1/2:
LOC - 7
FOT - 2
SGH - 19
RI - 32
MEL - 7
TS - 12
Total B1/2- ...
Copy link to clipboard
Copied
I'm sorry but it is not clear at all. How can you calculate "how many times" something is selected when you say you only have one dropdown? The names Chapter0.0, Chapter0.1, Chapter1.0 and Chapter1.1 are not friendly to looping through the names because the parts before the periods are different. You would have to put them in an array and loop through like this:
var flds=["Chapter0.0","Chapter0.1","Chapter1.0","Chapter1.1"]
var ttl=0;
for(var i=0;i<flds.length;i++)
{
if(this.getField(flds[i]).value=="LOC"){ttl++}
}
event.value=ttl;
Copy link to clipboard
Copied
How odd, I must have done something wrong in the creating multiple copies. So I've done it again using "Chapter" rather than Dropdown, setting up a whole new formula and copying yours, but it just comes up with 0. I have taken the liberty of attaching the file in case that makes it clearer! Thanks for your help.
Copy link to clipboard
Copied
You didn't tell me you had export values in the dropdowns. The value of a dropdown is its export value. Since all of your items have an export value of 1, that means none of the values will be "LOC" or any of the entries that display when you select them. The values will always be 1, so the script is calculating properly to 0.
You either have to remove all the export values, OR change the script to the following:
var ttl=0;
for(var i=0;i<25;i++)
{
if(this.getField("Chapter."+i).getItemAt(this.getField("Chapter."+i).currentValueIndices,false)=="LOC")
{ttl++}
}
event.value=ttl;
You should also select "Commit selected value immediately" in the Options tab of each dropdown so the numbers in the calculation field change immediately when a new selection is made.
https://pdfautomationstation.substack.com/p/calculation-vs-validation-scripts-eb5
Copy link to clipboard
Copied
Amazing, thanks so much! In other calculations I've had to have an export value for it to add up. This works now. I am really grateful, thank you! I will take the export value out.
Copy link to clipboard
Copied
I have two separate dropdown fields and I need to caclculate how many times each option is selected in each field. So there will be several total fields:
B1 total
B2 total
B1/2 total
LOC total
SGH total
etc.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more