PDF If then code question
Copy link to clipboard
Copied
I'm trying to make a pdf order form that will calculate the total amount of a line item.
I have one variable that is the number of Trade Packets (TP), one variable that is the number of M packets (M), the unit price (UP), and the Amount (Amt). What I need is if one of the variables is empty it still calculates. The TP and M fields are one or the other, but not both as they are different qty in each.
So if I have 5 TP at $1.00 and the M field is blank, the amount would be $5.00
If I have 5 M at 10.00 and the TP field is blank, the amount would be $50.00.
Copy link to clipboard
Copied
The following script shoud do that. There is a potential problem if both M and TP are filled in, but you can catch that with another check upfront before you do the calculation and then display an error message instread of performing the calculation.
var m = this.getField("M").value;
var tp = this.getField("TP").value;
if (m != 0) {
event.value = m * this.getField("Amt").value * this.getField("UP").value;
}
else if (tp != 0) {
event.value = tp * this.getField("Amt").value * this.getField("UP").value;
}
else {
event.value = 0;
}

