Copy link to clipboard
Copied
I am new to calculations in Acrobat. I have a column of cells, some of which are calculated and some are entered manually. They are as follows:
CASH PRICE (is calculated as the sum of previous cells)
TAX (this amount is entered manually)
TOTAL CASH PRICE (is the sum of CASH PRICE and TAX)less:
CASH DOWN (this amount is entered manually)
TRADE VALUE (is calculated as the sum of previous cells)
BALANCE DUE (is calculated as TOTAL CASH PRICE - CASH DOWN - TRADE VALUE)
So, this is what I have for the BALANCE DUE cell, under 'Custom Calculation Script':
// Get first field value
var v1 = getField("TOTAL CASH PRICE").value;
// Get second field value
var v2 = getField("CASH DOWN").value;
// Get third field value
var v3 = getField("TRADE").value;
// Set this field value equal to the difference
event.value = v1-v2-v3;
This works fine, as long as an amount (even "0") is entered in the TAX and/or CASH DOWN cells.
My question is, how do I get the BALANCE DUE cell to calculate correctly, whether an amount is entered or if the cell is left blank (cell left blank=0)
Copy link to clipboard
Copied
This is a classic example of an incorrect calculation order. Many people assume that fields calculate in the correct order automatically, or based on their location on the page, or their tab order. They do not. There's a separate list that determines in which order the fields are calculated. You can find it in Form Edit mode, under the More button (or under Other Tasks, depending on your version of Acrobat).
Copy link to clipboard
Copied
You need to explicitly convert each variable to a number, so that even an empty value will be zero.
You do it like this:
var v1 = Number(getField("TOTAL CASH PRICE").value);
And the same with the other two, and then it should work.
Copy link to clipboard
Copied
Maybe I have something else wrong? It is still not functioning as I would like. If I don't enter a value into either the TAX or CASH DOWN cells, my BALANCE DUE cell is not calculating correctly. This is what I have:
// Get first field value
var v1 = Number(getField("TOTAL CASH").value);
// Get second field value
var v2 = Number(getField("CASH DOWN").value);
// Get third field value
var v3 = Number(getField("TRADE").value);
// Set this field value equal to the difference
event.value = v1-v2-v3;
Copy link to clipboard
Copied
Is the value of any of the other fields calculated as well? If so, check the Fields Calculation Order.
Copy link to clipboard
Copied
I don't know what you mean by this. I have tried changing the order of how things calculate, and I am not getting the results I'm after.
CASH PRICE -- is calculated as the sum of the previous cells.
BALANCE DUE does not add the last number entered ($6000) even though it has been calculated in the CASH PRICE cell -- which is the cell that the BALANCE DUE calculation uses.
If I enter a "0" in the cell following $6000, then the BALANCE DUE cell calculates correctly.
VALUE OF TRADE-IN -- is calculated as the sum of the previous cells ALSO
and it is causing the same outcome with the BALANCE DUE cell
Copy link to clipboard
Copied
This is a classic example of an incorrect calculation order. Many people assume that fields calculate in the correct order automatically, or based on their location on the page, or their tab order. They do not. There's a separate list that determines in which order the fields are calculated. You can find it in Form Edit mode, under the More button (or under Other Tasks, depending on your version of Acrobat).
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more