Skip to main content
danb8s
Participant
February 6, 2023
Question

PDF Form Calculations with Checkboxes & Discounts

  • February 6, 2023
  • 1 reply
  • 2064 views

I'm creating a PDF order form and have the following:

 

Four options with specific prices (TriFold = $3, 8-Page = $4, 12-Page = $6, 16-Page = $8).

Customers can only order one option. Ideally I'd use Radio Buttons instead of Checkboxes, but I can't get them to work with values, and our customers are really good about only ordering one option, so I'm OK with using Checkboxes.
There's also a Checkbox to allow us to design their item to receive a $1 per item discount. So if they order 100 TriFolds and have us design it, they pay $200 instead of $300. 

 

So far the issues I'm having are:

1. I can't get the form to calculate the Order Total by multiplying the quantity entered by the price of the item.

2. I can't figure out how to apply the discount, if the customer checks the box.

 

One idea I had is to simply have each option quantity field multiplied by the option price, and sum them; and if the Discount checkbox is checked, subtract the option quantity field amount from the total price. I'm having trouble figuring out the if/then scripting for this, though.
I know the basic (non-discounted) formula would be (TriFoldQty*3)+(8PageQty*4)+(12PageQty*6)+(16PageQty*8). Then I'd need an if/then test to subtract the discount, if it's checked. 

 

Any assistance would e greatly appreciated.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
February 6, 2023

Use radio buttons for the selection, where the export value of each button is the price.  Use pure numbers for the price, no "$".  

 

The radiobuttons have an added difficulty because if none of them are selected, the radio button field has a non-numerical value. A script is necesary to handle this situation;

Here's an example calculation script for the "Order Total" fields.  The field names I've used are made up and you'll need to replace them with the real names from your form.

 

var nQty = this.getField("Quantity").value;
var nPrice = this.getField("PageOptions").value;
if(nPrice != "Off")
   event.value = nPrice * nQty;
else
   event.value = "";

 

 

Don't worry about the discount for now, get the "Order Total" working first. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
February 6, 2023

var nPrice = this.get("PageOptions").value;

Should of course be:

var nPrice = this.getField("PageOptions").value;