Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Summation box from dropdowns

Participant ,
Jan 08, 2025 Jan 08, 2025

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!

TOPICS
PDF forms
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2025 Feb 16, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 17, 2025 Feb 17, 2025

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2025 Feb 17, 2025
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 15, 2025 Feb 15, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2025 Jan 08, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 08, 2025 Jan 08, 2025

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2025 Jan 08, 2025

No.  That is referring to importing field values from a text file.  Separate issue.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 08, 2025 Jan 08, 2025

Ok thanks, sadly not going to sort my issue then, I think it's just a complex document!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 08, 2025 Jan 08, 2025

I've tried doing that with LOC as an example but nothing appears in the 'total' field...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 08, 2025 Jan 08, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2025 Jan 08, 2025

That error means one of the fields named in your script does not exist.  Please post your script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 08, 2025 Jan 08, 2025

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2025 Jan 08, 2025

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".  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 08, 2025 Jan 08, 2025

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- ...

 



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2025 Jan 08, 2025

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;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2025 Jan 09, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2025 Jan 09, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2025 Jan 09, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 09, 2025 Jan 09, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines