These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Help with Javascript Calculation for a Tax Form

deano717
Registered: Nov 11 2008
Posts: 4
Answered

I am working on a tax form and I need help leaving a field blank if the calculation returns a negative number.

The form has this comment

"Line 14 minus Line 18, minus Line 20, Leave blank if less than $1.00"

I am using this code which works correctly. However, I want the field to be blank if the result is less than 1

var a = this.getField("Tax Liability").value; // variable for the Line 14 Tax Liability
var b = this.getField("Total Tax Est").value; //Line 18 Total Tax Est
var c = this.getField("Credit from Spouse A").value; // Line 20 Credit from Spouse A
event.value = a - b - c; // compute Line 22 for Tax Due A

Thanks!!

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
After you have the result of the calculation you can test the result and if necessary change the value:

var a = this.getField("Tax Liability").value; // variable for the Line 14 Tax Liability
var b = this.getField("Total Tax Est").value; //Line 18 Total Tax Est
var c = this.getField("Credit from Spouse A").value; // Line 20 Credit from Spouse A
event.value = a - b - c; // compute Line 22 for Tax Due A
if (event.value < 1) event.value = ''; // if the result is less then $1 tax liabilty then null field value

George Kaiser

deano717
Registered: Nov 11 2008
Posts: 4
Perfect! That was it! You are truly amazing and speedy!