2 Replies Latest reply on Jun 15, 2016 9:10 AM by brya34

    Text field subtraction

    brya34

      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.

        • 1. Re: Text field subtraction
          Karl Heinz Kremer Adobe Community Professional

          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.

          1 person found this helpful
          • 2. Re: Text field subtraction
            brya34 Level 1

            Thank you so much, it worked perfectly!