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

Text field subtraction

Guest
Jun 15, 2016 Jun 15, 2016

I have 3 text fields in a pdf and I named them each Adjustments_1 , Adjustments_2 and Adjustments_3. I want Adjustments_3 to equal  Adjustments_1 - Adjustments_2 and if that difference is less than 0, I want Adjustments_3 to equal "0" and have that difference displayed on the text fields. I tried doing an if else statement under the custom calculation script in the Adjustments_3 properties which looks like this:

if (Adjustments_2 < Adjustments_1) {

Adjustments_3=Adjustments_1-Adjustments_2;

}

else {

Adjustments_3 = "0";

}

My difference is always 0.00 for any value I try, so I'm just wondering where I went wrong.

TOPICS
Acrobat SDK and JavaScript , Windows
603
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

correct answers 1 Correct answer

Community Expert , Jun 15, 2016 Jun 15, 2016

You cannot access the value of a field by just using the field name. The correct way to get the value of a field is this:

this.getField("Adjustment_1").value

So, to convert your calculation to this mechanism, by also introducing JavaScript variables, the script would look like this:

var Adjustment_1 = this.getField("Adjustment_1").value;

var Adjustment_2 = this.getField("Adjustment_2").value;

var Adjustment_3;

if (Adjustments_2 < Adjustments_1) {

    Adjustments_3=Adjustments_1-Adjustments_2;

}

else {

   

...
Translate
Community Expert ,
Jun 15, 2016 Jun 15, 2016

You cannot access the value of a field by just using the field name. The correct way to get the value of a field is this:

this.getField("Adjustment_1").value

So, to convert your calculation to this mechanism, by also introducing JavaScript variables, the script would look like this:

var Adjustment_1 = this.getField("Adjustment_1").value;

var Adjustment_2 = this.getField("Adjustment_2").value;

var Adjustment_3;

if (Adjustments_2 < Adjustments_1) {

    Adjustments_3=Adjustments_1-Adjustments_2;

}

else {

    Adjustments_3 = "0";

}

this.getField("Adjustment_3").value = Adjustment_3;

As you can see, I've left your script intact, and created variables with the names that you've used, but either assigned these variables based on the field value, or assigned the field value based on the variable Adjustment_3.

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
Guest
Jun 15, 2016 Jun 15, 2016
LATEST

Thank you so much, it worked perfectly!

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