12 Replies Latest reply on Jun 20, 2017 3:27 AM by Zaid Al Hilali

# Form field calculation

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?

• ###### 1. Re: Form field calculation

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

What format is the date field using?

• ###### 2. Re: Form field calculation

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.

• ###### 3. Re: Form field calculation

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

• ###### 4. Re: Form field calculation

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

• ###### 5. Re: Form field calculation

"value" gives the same value.

• ###### 6. Re: Form field calculation

But you didn't include either one in your code, so it's not going to work as-is...

• ###### 7. Re: Form field calculation

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;

• ###### 8. Re: Form field calculation

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;
```
• ###### 9. Re: Form field calculation

OK, I forget it.

• ###### 10. Re: Form field calculation

Perfect. It worked.