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

Calculation - Can I deactivate form fields from beeing counted?

Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hi,

 

I have a list of items and each item has a point value that is summed up in a "Total" calculation.

 

Is there a way that I can deactivate one or more items from beeing counted? Perfect would be a checkbox for each item, that I could click and the item would not be counted - without having to delete the item.

 

And if I uncheck the checkbox it would be counted again?

 

Tim

TOPICS
Acrobat SDK and JavaScript

Views

307

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Apr 30, 2020 Apr 30, 2020

Yes, that is possible, using a script. You would need to iterate over the check-boxes and if they are ticked then you add the value of the corresponding text field to the total, and apply the total to the calculating field at the end of the process.

This is not too complicated, provided the names of the check-boxes and text fields are matching and consistent.

For example, if they are called CB1, Text1, CB2, Text2, etc. then you can use this code as the custom calculation script of the total fiel

...

Votes

Translate

Translate
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Yes, that is possible, using a script. You would need to iterate over the check-boxes and if they are ticked then you add the value of the corresponding text field to the total, and apply the total to the calculating field at the end of the process.

This is not too complicated, provided the names of the check-boxes and text fields are matching and consistent.

For example, if they are called CB1, Text1, CB2, Text2, etc. then you can use this code as the custom calculation script of the total field to do it (let's assume there are 20 such sets of fields):

 

var total = 0;
for (var i=1; i<=20; i++) {
	if (this.getField("CB"+i).valueAsString!="Off") total+=Number(this.getField("Text"+i).valueAsString);
}
event.value = total;

Votes

Translate

Translate

Report

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
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

That sounds very promising.

Is it possible to handle it the other way around?

So the values are not counted when the checkbox is ticked?

Would I have to set valueAsString!=  to "On" ?

Votes

Translate

Translate

Report

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

You have the correct idea, but the default On value (i.e. export value) for a checkbox is "Yes".

However, the best strategy is to change the comparsion condition to 

 

valueAsString == "Off"

 

The reason for this is that "Off" is always the Off value for a checkbox. So this code will work, regardless of the actual export value from the checkbox. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

LATEST

ok - I understand.

Once more - thank you very much for your support!

Tim

Votes

Translate

Translate

Report

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