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);}
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);
Copy link to clipboard
Copied
What is the export value of the checkbox?
Copy link to clipboard
Copied
Yes. Should it instead be "On"?
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);
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!
Copy link to clipboard
Copied
Do you have any other scripts that could affect that checkbox?
Can you share your file?
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!
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.
Copy link to clipboard
Copied
Thank you so much for your help!

