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

How many dropdown fields you have, and what are the names?

You want to result show in separate fields for each selection?

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 have two dropdowns which should be selected:

1 - Chapter

LOC

FOT

SGH

RI

MEL

TS

 

These need to be added up individually.

 

2 - Licence

B1

B2

B1/B2

 

These also need to be added up individually (i.e. B1 total, B2 total, B1/B2 total)

 

At the very end of my document I have a totals page where I want to show:

LOC (total) -  B1 LOC (total) B2 LOC (total) B1/B2 LOC (total)

FOT (total) -  B1 FOT (total) B2 FOT (total) B1/B2 FOT (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
Community Expert ,
Jan 08, 2025 Jan 08, 2025

From your original question:

"so you can see that 'FOC' was selected 30 times, 'LOC' was selected 12 times, etc."

But then here you say you only have 2 dropdowns.  Please clarify.

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 have two dropdowns which I need to calculate: Chapter and Licence.

Chapter has 6 options to choose from.

Licence has 3 options to choose from.

I need to total these both separately and together.

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

At the very end of my document I have a totals page where I want to show:

LOC (total) - B1 LOC (total) B2 LOC (total) B1/B2 LOC (total)

FOT (total) - B1 FOT (total) B2 FOT (total) B1/B2 FOT (total)

etc.
What exactly are you trying to calculate since you have only two dropdowns?

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 hopefully clarified under the other post, but I have about 40 tasks to fill in. Each one is under a Chapter (LOC, SGH, etc.) and also has a Licence (B1, B2, B1/B2). I need to calculate both separately, and in combination.

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 14, 2025 Feb 14, 2025

Me again! I have been trying to create a script to add up dropdowns based on this thread.

 

I created 260 dropdowns to enable me to calculate the following:

 

var ttl=0;
for(var i=0;i<260;i++)
{
if(this.getField("Task_dropdown."+i).value=="LOC B1-B2")
{ttl++}
}
event.value=ttl;

 

The box is showing as 0. I have removed the export values.

 

I get this message:

TypeError: f is null
1282:byteCodeToolCannot continue printing to the console.

 

Is anyone able to help please?

 

Thank you

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 14, 2025 Feb 14, 2025

That error means one of the fields in the loop doesn't exist.  Ensure your fields are name "Task_dropdown.0" through "Task_dropdown.259" or change the 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 ,
Feb 14, 2025 Feb 14, 2025

When I created copies, it started putting numbers and then other numbers after the dots. So for some reason I have fields named something like this: "Task_dropdown.25.9"

 

Despite the fact that my dropdown was only called Task_dropdown

 

Was this because I created multiple copies across, as well as down - as I need a heck of a lot of them?!

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 14, 2025 Feb 14, 2025

Just realised this is the same problem I had last time when I started this! The "." appearing out of nowhere.

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 14, 2025 Feb 14, 2025

Yes.

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 14, 2025 Feb 14, 2025

BLIMEY. This stuff really isn't easy. Thank you

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 14, 2025 Feb 14, 2025

Will the other fields work if they are formatted thus:

Task_dropdown.0.0.0.1 

etc

as otherwise I am going to have to rename them all individually?

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 14, 2025 Feb 14, 2025

No.  The field name in the script this.getField("Task_dropdown."+i).  The i is the number in the loop:

"Task_dropdown.0"

"Task_dropdown.1"

"Task_dropdown.2"

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
Participant ,
Feb 14, 2025 Feb 14, 2025

OK thanks for clarifying... this is going to take an AGE.

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 14, 2025 Feb 14, 2025

Do you have other dropdowns, aside from the ones you want to count in this script, that have "Dropdown" in the names, or are these the only ones?

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 14, 2025 Feb 14, 2025

These are the only ones.

I will have several scripts adding up LOC B1-B2, LOC B1, LOC B2, TS B1-B2, etc but only using these fields. These are the only ones with Dropdown in the name.

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 14, 2025 Feb 14, 2025

Use the following custom calculation script in the text field:

var ttl=0;
for(var i = 0; i < this.numFields; i++)
{
var fieldName = this.getNthFieldName(i);
if(fieldName.split(".")[0]=="Dropdown")
{
var oFld=this.getField(fieldName);
if(oFld==null){continue}
if(oFld.value=="LOC B1-B2"){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 ,
Feb 14, 2025 Feb 14, 2025

Thank you SO MUCH. It looks like this may solve all my problems. It works and now I'm applying it for the rest of the fields.

Could I ask you to explain the breakdown to me please so I can try to learn it myself?

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 14, 2025 Feb 14, 2025

 

 

var ttl=0; //set a counting variable to zero.
for(var i = 0; i < this.numFields; i++)//loop through all the fields
{
var fieldName = this.getNthFieldName(i);//get the nth field name
/*split the field name by periods into an array, get the first array element and test whether it is equal to "Dropdown"*/
if(fieldName.split(".")[0]=="Dropdown")
//if true:
{
/*get the field object with the field name*/
var oFld=this.getField(fieldName);
/*test whether field object is null (sometimes the fields are gone but the names remain, which will cause an error.  If null, loop goes back to beginning.*/
if(oFld==null){continue}
/*test the field value for string in quotes.  If true, increment the counting variable by 1.*/
if(oFld.value=="LOC B1-B2"){ttl++}
}
}
//set field value to the counting variable.
event.value=ttl;

 

 

If you are interested, message me privately for a discount code for my (paid) scripting course.

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 15, 2025 Feb 15, 2025

I will do, thank you. Apologies, had I known you offered a course I wouldn't have asked you for such info for free!

 

So the script works beautifully, but the document is now VERY slow. And my date fields keep reverting to being 'text' fields for some reason - I have no idea why that is happening. Do I just swallow the slowness as the price you pay for having it work well, or is there any way to speed it up please?

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 15, 2025 Feb 15, 2025

ETA I have turned it off while editing the document, which helps. I guess I can send instructions to the person who is filling in the form on how to turn it off and then turn it back on for calculations at the end. The article linked to earlier provides a script, but I can't get that to work.

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

What is ETA, and what is 'it' that you have turned off?  Since that is a calculation script it is going to run every time any field value changes, along with any other calculations you have in your form.  If this field is the issue you could speed up performance by moving the script to a mouse up action in a button that you label "Calculate" and it will only run when the user clicks the button.  Keep in mind that you will have to change event to this.getField("ThefieldNameWhereTheCalculationIsNow").  Here's an article on form performance:

https://pdfautomationstation.substack.com/p/pdf-calculation-tricks

 

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 16, 2025 Feb 16, 2025

ETA means "edited to add". I turned off Javascript as the file simply kept crashing so I will try a button! Do I have to have Javascript on for that to work?

I read that article originally, but when I tried putting the calculation in that is mentioned in there it didn't work.

I wanted to use this as a template for other documents - but I tried copying fields across from another PDF and it didn't work. So it looks like I am not going to be able to do that, and that's soul destroying to be honest. 😄

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