Skip to main content
Participant
December 16, 2019
Answered

Fillable PDF If Then Calculation Help

  • December 16, 2019
  • 1 reply
  • 419 views

Hi all,

 

I have a fillable PDF which I want to be able to calculate the total cost for based on how many units of products a customer wants to buy. Here is my scenario:

 

I have a table with four columns.

  • ColumnA - is the number of units (this can be filled out by end-user)
  • ColumnB - Has the per-unit price based on an order of 1-10 items (this is a read-only field)
  • ColumnC - Has the per-unit price based on an order of 11+ items (this is a read-only field)
  • ColumnD - (should) Calculate the total cost based on the number of units (ColumnA) times the appropriate per-unit price (ColumnB OR ColumnC). This is also a read-only field.

 

My question is, for ColumnD what is the appreciate javascript that needs to be used in the custom calculation?

 

Thanks in advance for any feedback!

This topic has been closed for replies.
Correct answer try67

You can use this code as the custom calculation script of ColumnD:

 

var numUnits = Number(this.getField("ColumnA").valueAsString);
var cost = (numUnits<11) ? Number(this.getField("ColumnB").valueAsString) : Number(this.getField("ColumnC").valueAsString);
event.value = numUnits * cost;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 16, 2019

You can use this code as the custom calculation script of ColumnD:

 

var numUnits = Number(this.getField("ColumnA").valueAsString);
var cost = (numUnits<11) ? Number(this.getField("ColumnB").valueAsString) : Number(this.getField("ColumnC").valueAsString);
event.value = numUnits * cost;
AnthonyLGAuthor
Participant
December 16, 2019

Thanks!