Skip to main content
Participant
November 4, 2024
Question

Checkbox calculation issues in Acrobat

  • November 4, 2024
  • 3 replies
  • 517 views

Been scouring the forum to find a solution but been unable to replicate the solution on my own (see graphic). I'm trying to populate usdcost with usmsrp and an option to apply a 50% or 40% discount. Even trying one checkbox yielded no result for me. I trued adding the following code into the usdcost field:

 

var m40 = even.target;
var usmsrp = this.getField(“usmsrp”).value;

if (m40.value !== "Off") {

this.getField(“usdcost”).value = usmsrp - (usmsrp * .40);

} else {

this.getField(“usdcost”).value = 0;

}

 

Is there a way that I can add both checkboxes? Thank you in advance.

 

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
November 5, 2024
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
November 4, 2024

event.target is the field containing the script.  In your case, usdcost.  My recommendation is to change the check box names to the same thing (example:  Discount) and set their export values to .5 and .6 respectively.  Then enter the following custom calculation script in usdcost:

var oFld=this.getField("Discount");

var discount=1;

if(oFld.value!="Off")

{discount=oFld.value}

event.value=this.getField("usmsrp").value * discount;

garrrAuthor
Participant
November 7, 2024

That solution worked beautifully. Is it possible to leave the field usdcost blank if no amount is entered in the field usmsrp?

I tried the adding the snippet: 

else event.value = ""; with and without curly brackets and I kept receiving error messages.

PDF Automation Station
Community Expert
Community Expert
November 7, 2024
var oFld=this.getField("Discount");
var discount=1;
if(oFld.value!="Off")
{discount=oFld.value}
if(!this.getField("usmsrp").value)
{event.value=""}
else
{
event.value=this.getField("usmsrp").value * discount;
}
Bernd Alheit
Community Expert
Community Expert
November 4, 2024

Check the Javascript console for errors.