Adding a checkbox for rush order calculation

Community Beginner ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

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

120

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
community guidelines

correct answers 1 Correct answer

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);

Likes

Translate

Translate
Community Expert ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

What is the export value of the checkbox?

 

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

Copy link to clipboard

Copied

Yes. Should it instead be "On"?

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
community guidelines
Community Expert ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

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);

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

Copy link to clipboard

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!

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
community guidelines
Community Expert ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

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

Can you share your file?

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

Copy link to clipboard

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!

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
community guidelines
Community Expert ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

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.

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

Copy link to clipboard

Copied

LATEST

Thank you so much for your help!

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
community guidelines