Skip to main content
Inspiring
April 13, 2022
Answered

Adding a checkbox for rush order calculation

  • April 13, 2022
  • 2 replies
  • 1917 views

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

This topic has been closed for replies.
Correct answer Nesa Nurani

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

2 replies

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
April 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);

sdbrakkeAuthor
Inspiring
April 13, 2022

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!

Nesa Nurani
Community Expert
April 13, 2022

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

Can you share your file?

Bernd Alheit
Community Expert
April 13, 2022

What is the export value of the checkbox?

 

sdbrakkeAuthor
Inspiring
April 13, 2022

Yes. Should it instead be "On"?