Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PDF If then code question

New Here ,
Jul 06, 2022 Jul 06, 2022

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.

 

pdf Java.pngexpand image

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms
206
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2022 Jul 07, 2022
LATEST

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines