Highlighted

Check Box Value calculation

Explorer ,
Sep 27, 2020

Copy link to clipboard

Copied

I have 4 checkbox fields check1,check2...etc all has export value of 1. If I use SFN or value is, it calculates them correctly but I can't figure out how to calculate values  in custom calculation script.

TOPICS
Acrobat SDK and JavaScript

Views

146

Likes

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

Check Box Value calculation

Explorer ,
Sep 27, 2020

Copy link to clipboard

Copied

I have 4 checkbox fields check1,check2...etc all has export value of 1. If I use SFN or value is, it calculates them correctly but I can't figure out how to calculate values  in custom calculation script.

TOPICS
Acrobat SDK and JavaScript

Views

147

Likes

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
Sep 27, 2020 1
Adobe Community Professional ,
Sep 27, 2020

Copy link to clipboard

Copied

Can you explain what type of calculation you want to perform? It is a simple sum of the values of the checkboxes, or something else. If a simple sum, why do you want to use a custom script? In any case, with a script you can retrieve the value of each, ignore any that have a value of "Off", and add those that are not, after converting them to a number.

Likes

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
Reply
Loading...
Sep 27, 2020 0
Explorer ,
Sep 28, 2020

Copy link to clipboard

Copied

I want to add to folowing script if 2 of the checkboxes are checked total*.80

var total = 0;
for (var i=1; i<=4; i++) {
if (this.getField("checkbox"+i).value=="1") {
total+=this.getField("checkbox"+i+"-price").value;
}
}
event.value = total;

Likes

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
Reply
Loading...
Sep 28, 2020 0
Adobe Community Professional ,
Sep 28, 2020

Copy link to clipboard

Copied

Then that last line could be:

 

event.value = total > 1 ? 0.8 * total : total;

Likes

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
Reply
Loading...
Sep 28, 2020 0
Explorer ,
Sep 28, 2020

Copy link to clipboard

Copied

Sorry I thought it will be clear from the code, I can't use that because total is from text fields not checkboxes, when checkbox is checked it add text field value to total.There is 4 checkboxes and 4 text fields (5th been where code go).

Likes

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
Reply
Loading...
Sep 28, 2020 0
Explorer ,
Sep 28, 2020

Copy link to clipboard

Copied

I'm getting missing before statement error.

Likes

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
Reply
Loading...
Sep 28, 2020 0
Engaged ,
Sep 28, 2020

Copy link to clipboard

Copied

In the last line of code change first : with ? 

Likes

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
Reply
Loading...
Sep 28, 2020 0
Marietaa LATEST
Explorer ,
Sep 28, 2020

Copy link to clipboard

Copied

Thanks George and Nesa that worked.

Likes

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
Reply
Loading...
Sep 28, 2020 0