Skip to main content
Participant
July 12, 2024
Answered

Calculating order form total column using Javascript

  • July 12, 2024
  • 1 reply
  • 741 views

Hi

Apologies, I know nothing about Javascript.

I have an order form in Acrobat that I need to calculate a total with Goods and Services Tax (GST) attached image.

Staff members enter quantity (QTY) and unit price (UNITPRICE). They then choose Y or N to whether the unit price is inclusive of GST.

So, therefore the TOTAL column needs to calculate

If GST = Y

Then multiply QTY by UNITPRICE

Else multiply QTY by (UNITPRICE*1.1)

I know that I need to use javascript with a IF and THEN statements in the 'Custom Calculation Script' section, just not sure how to script it.

 

Thanks

Michael

This topic has been closed for replies.
Correct answer PDF Automation Station

Assume your check boxes are named "GST" (name them identically, but set the export values in the options tab to 1 for No and 1.1 for Yes.  At the top of the Total field calculation tab select Value is the product of and select the 3 fields.  The calculation will take the unchecked boxes as zero so it will calculate to zero until the user checks whether there is GST or not.  If you don't want a zero value when the GST boxes are not checked, use the following custom calculation script instead:

var gst=1;

if(this.getField("GST").value!="Off")

{gst=this.getField("GST").value}

event.value=this.getField("QTY").value * this.getField("UNITPRICE").value*gst;

 

If you want to modify the script above once, so you don't have to modify for each Total field you can enter a script that antipates what the field names will be when you create all the rows from the first row using Right-click>Create multiple copies.  This article explains exactly how to do it, with video.

 

1 reply

PDF Automation Station
Community Expert
Community Expert
July 12, 2024

Assume your check boxes are named "GST" (name them identically, but set the export values in the options tab to 1 for No and 1.1 for Yes.  At the top of the Total field calculation tab select Value is the product of and select the 3 fields.  The calculation will take the unchecked boxes as zero so it will calculate to zero until the user checks whether there is GST or not.  If you don't want a zero value when the GST boxes are not checked, use the following custom calculation script instead:

var gst=1;

if(this.getField("GST").value!="Off")

{gst=this.getField("GST").value}

event.value=this.getField("QTY").value * this.getField("UNITPRICE").value*gst;

 

If you want to modify the script above once, so you don't have to modify for each Total field you can enter a script that antipates what the field names will be when you create all the rows from the first row using Right-click>Create multiple copies.  This article explains exactly how to do it, with video.

 

Participant
July 12, 2024

Thank you @PDF Automation Station, your help is much appreciated.

Have a great day!