5 Replies Latest reply on Jan 11, 2018 3:35 AM by try67

    Disable Javascript warning window?

    marceloj76273720

      Hello,
      I made a pdf form that has a table that has calculated fields, in them there is a formula that takes the data from the fields of its line and the result serves as the starting value of the lower line.
      But since at the beginning there are not all the fields with their respective values, the formula lacks arguments and the Javascript warning sale appears informing me of it.
      Is there any way to disable the Javascript warning window?
      Thank you so much

       

        • 1. Re: Disable Javascript warning window?
          Thom Parker Adobe Community Professional

          The solution is to either default the field values so that the calculation completes without error, or use a script for the calculation that includes checks on the input values.

           

          Could you post a screenshot of the warning window?

          • 2. Re: Disable Javascript warning window?
            JR_Boulay Adobe Community Professional

            Another solution is to not use an automatic calculation and use a button that the user will press to calculate.

            • 3. Re: Disable Javascript warning window?
              gkaiseril MVP & Adobe Community Professional

              You can use the "if ... then ... else" statement to control the running a custom calculation script. You need to come up with a procedure to differentiate between the field not having an valid value for processing and one fore which a valid value does not exist. Usually this is done by testing a field's string value to see if it is a null string, "", or a zero value. A null value would only exist if there has been no calculation performed  and a zero value would indicate that the row has had the calculation performed. Since the final calculation is dependent upon the calculation for the row, you will need to preform this test for the calculation for the row. You need to be aware that the value for a null string in a field formatted as a number is zero just like the calculated value zero. To differentiate between a null string value and a zero value one uses the "valueAsStirng" property and not the "value" property. In a table of repeated calculations I would create a document level function to take the variable input values and return the result of the calculation to the calling of the function The function would return a null string if the calculation was not performed and the numeric result of the calculation if the calculation had been performed. All of this will require the use of custom JavaScript code.

              • 4. Re: Disable Javascript warning window?
                marceloj76273720 Level 1

                Thank you all for your ideas,
                Attached is the link to the pdf that I am creating with the table and the form with all its fields.
                As you can see the option of assigning default values to all the fields involved in the final calculation I have already done so, however the warning message continues to appear.
                In order to understand the concept a bit better, I commented that the table calculates the loss of load in a natural gas pipeline; the nodes represent specific points of the installation where an equipment is installed, for example.
                The form is for general use, in various conditions, for which the user may need to fill only the first line (one node) or can use all of them.
                But every time you enter a value, whatever the field, the javascript performs the entire calculation and that is where the warning message appears so annoying.

                Formula.pdf - Google Drive

                • 5. Re: Disable Javascript warning window?
                  try67 MVP & Adobe Community Professional

                  There's a mathematical error in your code. You're in effect performing a division by zero, even if it doesn't look like it.

                  The error comes from this part of the formula (I'm taking "Dp A" as an example):

                  Math.pow(this.getField("D A").value, -4.82)

                  This is identical to 1/(x^4.82), x being the value of the field. But when the field is empty, this value is zero, and the result is:

                  1/(0^4.82) = 1/0

                  Which is illegal.

                   

                  The solution is to add an if-condition that only performs this calculation if "D A" is not empty or zero, like this:

                  if (Number(this.getField("D A").valueAsString)==0) event.value = "";
                  else event.value = 
                       (25078 * 0.6 * (this.getField("Le A").value) * 
                       (Math.pow(this.getField("Q A").value, 1.82)) * 
                       (Math.pow(this.getField("D A").value, -4.82))) * 
                       (this.getField("FSA").value);
                  
                  1 person found this helpful