Skip to main content
Participant
July 7, 2017
Answered

How to create a custom script that will output a calculation but display 0 if the sum is a negative number Please Help!

  • July 7, 2017
  • 1 reply
  • 587 views

I am trying to create a custom javascript calculation that will do the following:

Caculate: Subtract AGI_Total - (Deductions +Exemptions) and the result would go into the Taxable_Income field

I can do this in the Simplified Field notation of the Taxable_Income field on the PDF form I am working on but what I am having trouble doing is if the sum equals a negative number, I want the Taxable_Income field to display 0. Unfortunately, I am very new at Javascript and I don't know how exactly to do this. I am using Adobe Acrobat Pro.

Can someone help please?

This topic has been closed for replies.
Correct answer try67

Use this code as the field's custom calculation script:

var result = Number(this.getField("AGI_Total").value) - (Number(this.getField("Deductions").value) + Number(this.getField("Exemptions").value));

if (result<0) result = 0;

event.value = result;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 7, 2017

Use this code as the field's custom calculation script:

var result = Number(this.getField("AGI_Total").value) - (Number(this.getField("Deductions").value) + Number(this.getField("Exemptions").value));

if (result<0) result = 0;

event.value = result;

Andy851Author
Participant
July 7, 2017

It works! Thank you! and thank you for the speedy response!