3 Replies Latest reply on Oct 24, 2009 8:41 AM by gkaiseril

    Preventing a calculation




      I'm very new to this so this will hopefully be an easy on for many of you.


      I have set up a form in a PDF in Acrobat Pro 5.0 that calculates two other form fields (Product Weight and Tare Weight).  This is the script:


      var p = this.getField("Product Weight");
      var t = this.getField("Tare Weight");
      event.value = p.value - t.value


      My problem is that this will recalculate everytime the file is saved even if the values entered in the two fields were not changed. I have this integrated with another application that has an Audit Trail - whenever the PDF file is saved, the calculation fires the audit trail saying that the calculation field was changed from "0" to "<the new calculated value>" even though nothing was changed in the fields.


      How could i set it up to ONLY calculate and recalculate if there are non-0 numbers entered in either of the two fields or if either of the numbers entered were changed?


      Thanks for your help.



        • 1. Re: Preventing a calculation
          try67 MVP & Adobe Community Professional

          I don't think you tell Acrobat when to calculate the form fields. However, you can add a codition in your script that doesn't apply the new value if it's identical to the present value.

          Maybe that will solve your problem.

          • 2. Re: Preventing a calculation
            try67 MVP & Adobe Community Professional

            Actually, there might be another way. You can try setting the event.rc property to false. That should stop the event from committing.

            • 3. Re: Preventing a calculation
              gkaiseril MVP & Adobe Community Professional

              The Acrobat JS API Reference discusses the order and way event processing occurs and what the various event processes are. One could perform the calculation as a "Blur" action for each of the input fields used in the calculation. so the calculation is only performed when an input field exited. In this manner the calculation would only be performed when one of the input fields is accessed and exited.