Skip to main content
Participating Frequently
January 31, 2025
Answered

Help needed with calculating discount

  • January 31, 2025
  • 2 replies
  • 1864 views

I'm working on a fillable PDF and apparently need custom calculation(s).  Thanks in advance for your advice. 

 

On the sample form provided, business cards can be ordered for one to four people, with quantity of 500 or 1000. The one-box and multiple-box prices are unique to the order quantities. When more than one set of 500 cards is ordered, the price is reduced for ALL sets of 500 cards (not just the 2nd, 3rd, or 4th). Same process when ordering a set of 1000 cards. For either order quantity, the cost reduction is $6 per box.  The "Line Total" field needs to show the combined, adjusted cost of cards.

 

On the lower half of the attached order form there are eight spots for ordering ID badges.  A quantity of one badge is assumed.  Without a form field for entering a quantity in each of the eight spots, can the "Name" field be given a value of one when a name is entered?

 

 

Correct answer Nesa Nurani

To calculate price, use this as custom calculation script:

var c500 = 0;
var c1000 = 0;
var total = 0;

for(var i=1; i<=4; i++){
var qty = this.getField("BC"+i+"Quantity").valueAsString;
if(qty == "500")c500++;
if(qty == "1000")c1000++;}

if(c500 == 1){
total += 65;}
else if(c500 > 1){
total += c500 * 59;}

if(c1000 == 1){
total += 75;}
else if(c1000 > 1){
total += c1000 * 69;}

event.value = total;


Use this in 'Quantity' field as custom calculation script, it will add 1 when name field is filled:

var count = 0;

for(var i=9; i<=16; i++){
var f = this.getField("Name_"+i).valueAsString;
if(f !== "")count++;}

event.value = (count == 0)? "" : count;

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 31, 2025

To calculate price, use this as custom calculation script:

var c500 = 0;
var c1000 = 0;
var total = 0;

for(var i=1; i<=4; i++){
var qty = this.getField("BC"+i+"Quantity").valueAsString;
if(qty == "500")c500++;
if(qty == "1000")c1000++;}

if(c500 == 1){
total += 65;}
else if(c500 > 1){
total += c500 * 59;}

if(c1000 == 1){
total += 75;}
else if(c1000 > 1){
total += c1000 * 69;}

event.value = total;


Use this in 'Quantity' field as custom calculation script, it will add 1 when name field is filled:

var count = 0;

for(var i=9; i<=16; i++){
var f = this.getField("Name_"+i).valueAsString;
if(f !== "")count++;}

event.value = (count == 0)? "" : count;
Participating Frequently
February 3, 2025

Thanks for your quick response.  I added the script to the custom calculation for "BCLineTotal" but I don't understand how it works, or how I need to rename fields so they are recognized by the script.  The quantity check boxes of 500 and 1000 are uniquely named for each of the four business card order areas. Top left quantities are named bc1500 and bc11000, bottom left quantities are named bc2500 and bc21000, etc etc.  The export value of bc1500 is 65, export value of bc11000 is 75.  I'm guessing that the field names don't work with the script.  If I name all of the 500 quantity check boxes the same, all four are selected when one is clicked.

For the ID badges, I entered that script in the "quantity" field.  In the IDbadgeLineTotal field, I entered (IDbadgeQuantity*12.5) in simplified field notation.  Also not working.  Your feedback is much appreciated.

 

Nesa Nurani
Community Expert
Community Expert
February 3, 2025

Scripts work fine with your original form, why did you change field names?

PDF Automation Station
Community Expert
Community Expert
January 31, 2025

I suggest changing the radio buttons to check boxes so that users can unselect if they change their mind about a section they have already selected.  Then change the export values to the price for a quantity of 1 instead of the quantity (65 and 75 instead of 500 and 1000).  Then enter the following custom calculation script in BCLineTotal:

 

 

var bc500=65;
var bc1000=75;
var count500=0;
var count1000=0;

for(var i=1;i<5;i++)
{
if(this.getField("BC"+i+"Quantity").value==65)
{count500++}
if(this.getField("BC"+i+"Quantity").value==75)
{count1000++}
}

if(count500>1){bc500=59}
if(count1000>1){bc1000=69}

event.value=bc500*count500 + bc1000*count1000;

 

 

This will work with radio buttons but the user won't be able to deselect a section.