Skip to main content
Zaid Al Hilali
Community Expert
Community Expert
June 20, 2017
Answered

Form field calculation

  • June 20, 2017
  • 2 replies
  • 1942 views

First of all, It is not clear to me whether I'm posting this question in the right forum.

I created an interactive fillable form, some fields should be filled by hand, calculations was done in Acrobat Pro to automatically displayed formula results.

Here is what is expected to happen in the red framed fields:

  1. QTY.: User will type-in the quantity being requested
  2. Requested date: User will type-in the request date (see #4 below)
  3. Unit Price: User to type-in Unit price
  4. Total Price: is an auto calculation. If "Request date" is 1st of June, then formula is as follows [ Qty x Unit Price ]. If the date is not 1st of June then formula should be as follows [ Qty x Unit Price / 2 ]

How can I make the Total Price to use If/Then formula, must this be scripted?

This topic has been closed for replies.
Correct answer try67

Thank you both @Bernd Alheit and try67​ for jumping in with the script. Unfortunately I'm getting this error after adding ".valueAsString"

The error reads: SyntaxError: missing ) after condition.

Below is the script I entered.

event.value = this.getField(" ??QTY. Adobe CC complete?? ").value * this.getField(" ??Unit Price Adobe CC complete?? ").value;

if (this.getField(" ??Request date?? ")  ".valueAsString" != "01/06/2017") event.value = event.value / 2;


Try this code:

var v = Number(this.getField("QTY. Adobe CC complete").value) * Number(this.getField("Unit Price Adobe CC complete").value);

if (this.getField("Request date").valueAsString!="01/06/2017") v = v/2;

event.value = v;

2 replies

Bernd Alheit
Community Expert
Community Expert
June 20, 2017

You must use JavaScript for this:

event.value = this.getField(" ??Qty?? ").value * this.getField(" ??Unit Price?? ").value;

if (this.getField(" ??Request date?? ") != "01/06/2017") event.value = event.value / 2;

In the code you must use the correct field names.

try67
Community Expert
Community Expert
June 20, 2017

Yes, this is the right place, and yes, this can be done using a script.

What format is the date field using?

Zaid Al Hilali
Community Expert
Community Expert
June 20, 2017

Qty and Unit Price fields are numbers only, while the Request date is dd/mm/yyyy

try67
Community Expert
Community Expert
June 20, 2017

You can use the code given above, then, just add ".valueAsString" after this part: this.getField(" ??Request date?? ")