## Adobe Community

• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit
• Calculate total fee based on number of selected ch...

# Calculate total fee based on number of selected checkboxes & fee amount fields

Explorer ,
Jan 29, 2024 Jan 29, 2024

Copy link to clipboard

Copied

Hi, I have a form with fields that states the fees that are based on the mumber of runs you select. There are checkboxes for each day for you to select the runs you want to do. You can select any combination of number & type of runs each day. If you do 1 run, the amount is one amount, your second run is a lower amount, your third run is a lower amount, & so-forth.

I can't assign fee amounts as the values to the checkboxes, because it is dependent on how many runs you do - and you you may not always choose STD as your first run & JWW as your second run, etc - you may choose JWW as your first run & FAST as your second run, etc.

I also can't just put the fee amounts in my entry fee calculation, because the fee amounts may change dependending on who is hosting the event - so I need my calculation to get the value entered in those fee fields, based on the the number of checkboxes checked by day, & total the days.

I'm guessing the logic of my calculation needs to be something like...

Day 1 (ifs... checkboxes for the day total 1, then fee field 1, checkboxes for the day total 2, then fee field 1 +  field 2, checkboxes for the day total 3, then fee field 1 + field 2 + field 3, etc) + Day 2 (ifs... checkboxes for the day total 1, then fee field 1, checkboxes for the day total 2, then fee field 1 +  field 2, checkboxes for the day total 3, then fee field 1 + field 2 + field 3, etc) + Day 3 (ifs... checkboxes for the day total 1, then fee field 1, checkboxes for the day total 2, then fee field 1 +  field 2, checkboxes for the day total 3, then fee field 1 + field 2 + field 3, etc) + Day 4 (ifs... checkboxes for the day total 1, then fee field 1, checkboxes for the day total 2, then fee field 1 +  field 2, checkboxes for the day total 3, then fee field 1 + field 2 + field 3, etc)

... but I don't know how to do that in JS. Also, does there need to be something to prevent an error if there isn't a Day 4, or isn't a fee in the 5th/6th runs for that event? Does there need to be something in the calculation to show "\$0.00" if nothing is checked?

Any help would be most appreciated - thanks!

TOPICS
JavaScript

Views

170

Report

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

## 1 Correct answer

Community Expert , Jan 30, 2024 Jan 30, 2024

Use this:

``````var total = 0;
var n1 = Number(this.getField("1st").valueAsString);
var n2 = Number(this.getField("2nd").valueAsString);
var n3_4 = Number(this.getField("3rd & 4th").valueAsString);
var n5_6 = Number(this.getField("5th & 6th").valueAsString);

function incrementD(index) {
var d = 0;
['STD', 'JWW', 'FAST', 'T2B', 'PremS', 'PremJ'].forEach(function(event) {
if (this.getField(index + " " + event).valueAsString !== "Off") {
d++;}}, this);

if (d >= 1) total += n1;
if (d >= 2) total += ``````
...

Votes

7 Replies 7
Explorer ,
Jan 29, 2024 Jan 29, 2024

Copy link to clipboard

Copied

This reply was originally to correct the typos in my original post, but I now have the option to edit my posts, so I edited my OP to remove the typos & this reply is no longer needed.

Votes

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 Expert ,
Jan 29, 2024 Jan 29, 2024

Copy link to clipboard

Copied

What are the field names or if you can share a file with us?

You want to show one total for all, or totals for each day separate?

Votes

Report

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

Copy link to clipboard

Copied

Checkbox names:

(+ same for Day 3 & Day 4)

Fee field names:

One total box for all days, field with text above "Entry Fee Enclosed" in original screenshot, field name "Fee".

Votes

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 Expert ,
Jan 29, 2024 Jan 29, 2024

Copy link to clipboard

Copied

If checkboxes for the day are 4 does it calculate 3rd & 4th twice or only once?

Votes

Report

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

Copy link to clipboard

Copied

Twice 🙂

Votes

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 Expert ,
Jan 30, 2024 Jan 30, 2024

Copy link to clipboard

Copied

Use this:

``````var total = 0;
var n1 = Number(this.getField("1st").valueAsString);
var n2 = Number(this.getField("2nd").valueAsString);
var n3_4 = Number(this.getField("3rd & 4th").valueAsString);
var n5_6 = Number(this.getField("5th & 6th").valueAsString);

function incrementD(index) {
var d = 0;
['STD', 'JWW', 'FAST', 'T2B', 'PremS', 'PremJ'].forEach(function(event) {
if (this.getField(index + " " + event).valueAsString !== "Off") {
d++;}}, this);

if (d >= 1) total += n1;
if (d >= 2) total += n2;
if (d >= 3) total += n3_4;
if (d >= 4) total += n3_4;
if (d >= 5) total += n5_6;
if (d == 6) total += n5_6;}

for (var i = 1; i <= 4; i++) {
incrementD(i);}

event.value = total;``````

Votes

Report

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

Copy link to clipboard

Copied

LATEST

Thank you sooooo much!! That worked perfectly!! 💙

Votes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources
About Adobe Acrobat
Adobe Acrobat Feature & Workflow
FAQs