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

# Adding a checkbox for rush order calculation

Community Beginner ,
Apr 13, 2022 Apr 13, 2022

Copied

Hello!

I am very new to javascript. I am using Acrobat DC Pro. I have successfully set up an order form that tallies up check boxes for each type of sample that is sent in (for a genetic test on animals s*m*n/colostrum/saliva), and collects total number of each type, and also successfully got the order for to total a sum of each checkbox and multiplied them with the cost. This worked fine!

Here comes the challenge (for me at least)! I was then tasked with adding an optional rush order option via a checkbox. This changes the amount from 35\$ a test to 50\$ a test. I am having a hard time figuring out how to accomplish this. Each time I try, it either keeps the amount of 50\$ from when the checkbox was checked and does not remove that calculations if the checkbox is then unchecked (say they changed their mind after seeing how much it would be etc). OR The checkbox comes unchecked on its own (weird) and none of the calculations work at all, but it still appropriately tallies up the boxes without cost.

I have the following code in the field where total cost is calculated. Is that correct? should I have something going on in the RushOrder checkbox field other than its value when clicked equaling Yes? What am I missing? What have I done wrong, etc? Any help would be appreciated!

This is the code I am using:

// Get field value, as a number from each type

var v1 = +getField("SemenSum1").value;

var v2 = +getField("SalivaSum1").value;

var v3 = +getField("ColostrumSum1").value;

//Checkbox rush order value

var RO = this.getField("RushOrder").value;

// Calculate and set this field's value to the result

if(getField("RO").value!="Yes"){
event.value = 50*(v1 + v2 + v3);}
else{event.value = 35*(v1 + v2 + v3);}

TOPICS
General troubleshooting , JavaScript , PDF forms

Views

734

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 , Apr 13, 2022 Apr 13, 2022

Try this:

var v1 = Number(this.getField("SemenSum1").value);
var v2 = Number(this.getField("SalivaSum1").value);
var v3 = Number(this.getField("ColostrumSum1").value);

if(this.getField("RushOrder").valueAsString == "Off")
event.value = 35*(v1 + v2 + v3);
else
event.value = 50*(v1 + v2 + v3);

8 Replies 8
Community Expert ,
Apr 13, 2022 Apr 13, 2022

Copied

What is the export value of the checkbox?

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 Beginner ,
Apr 13, 2022 Apr 13, 2022

Copied

Yes. Should it instead be "On"?

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 ,
Apr 13, 2022 Apr 13, 2022

Copied

Try this:

var v1 = Number(this.getField("SemenSum1").value);
var v2 = Number(this.getField("SalivaSum1").value);
var v3 = Number(this.getField("ColostrumSum1").value);

if(this.getField("RushOrder").valueAsString == "Off")
event.value = 35*(v1 + v2 + v3);
else
event.value = 50*(v1 + v2 + v3);

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 Beginner ,
Apr 13, 2022 Apr 13, 2022

Copied

Fantastic! This works in the calculation department...the calculations change as I check and uncheck. However, it appears as though the box remains checked even if I uncheck the box. Any ideas?

Thank You again for your prompt assistance!

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 ,
Apr 13, 2022 Apr 13, 2022

Copied

Do you have any other scripts that could affect that checkbox?

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 Beginner ,
Apr 13, 2022 Apr 13, 2022

Copied

Now when I take the file outside of acrobat pro dc, say open it in a browser, the rush order calculations do not work anymore.

In regards to other scripts that are calculations, I have another total cost field on the first page of the document, which is a duplicate of the one on the order form.

Thank you!

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 ,
Apr 13, 2022 Apr 13, 2022

Copied

I can check/uncheck checkbox and script works fine for me.

Javascript is probably not well supported in that browser, there is not much we can do about that.

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 Beginner ,
Apr 13, 2022 Apr 13, 2022

Copied

LATEST

Thank you so much for your help!