2 Replies Latest reply on Feb 27, 2008 9:38 AM by jay fresno

    subtract two fields

    jay fresno Level 2
      I need to subtract two fields (Field2 minus Field1) and add 1 digit to the total -- and have that total displayed in a third field named Sub1. If the user does not enter a number into Field2 or Field1, Sub1 needs to display a zero.

      I'm not experienced in Javascript, but I attempted to achieve this putting the script below into the Sub1 Custom Calculation Script -- which, unfortunately, is not working.

      var Sub1 = this.getField("Field2").value - this.getField("Field1").value +1;
      if (Sub1 == 1) event.value == 0;
      else event.value = "";

      I hope that someone can help out with a suggestion to make the Javascript work correctly.
        • 1. Re: subtract two fields
          gkaiseril MVP & Adobe Community Professional
          Let's get the order the requirememts in an orderly manner.

          First do we have the needed compute the difference?
          When we do,

          // check for values in field 1 and 2,
          // test for either field being balnk
          if (this.getField("1").valueAsString == "" | this.getField("2").valueAsString == "") {
          event.value = 0;
          else {
          // we have the data so we can compute the difference and add one
          // being careful to clearly state the order of the computation steps
          event.value = (this.getField("2").value - this.getField("1").value) + 1;
          • 2. Re: subtract two fields
            jay fresno Level 2
            Thank you so much for your reply. The calculation is now working, and I've learned something from this!