10 Replies Latest reply on Dec 11, 2013 12:59 AM by Angie_74

    Calculation not working

    Angie_74

      Hi

      I have a field (Tarief1) where I simply fill out a number.

      The 2nd field (Marge1) does nothing more then take the number of Tarief1 and place it in field Marge1.

      Which works, unless I go ahead and change the number in Tarief1.

      The field Marge1 will not refresh and take the new number from Tarief1.

       

      It may sound weird to have a field that does nothing more then copy the value of another field, but it is the way the form is set up and they want to keep it this way.

      Help is very much appreciated.

        • 1. Re: Calculation not working
          try67 MVP & Adobe Community Professional

          How are you copying the value, exactly?

          • 2. Re: Calculation not working
            Karl Heinz Kremer Adobe Community Professional

            Are you doing this with a calculation script in the target field? If not,

            how exactly are you copying the value?

             

            [ signature removed - promotional links are not permitted ]

            • 3. Re: Calculation not working
              Angie_74 Level 1

              In field Marge1 under Calculate, Simplified Field notations I have put: Tarief1

              • 4. Re: Calculation not working
                try67 MVP & Adobe Community Professional

                Is the value of "Tarief1" also calculated?

                • 5. Re: Calculation not working
                  Angie_74 Level 1

                  No Tarief1 is not a calculated field.

                  • 6. Re: Calculation not working
                    Angie_74 Level 1

                    Problem seems to be solved with the calculation order

                    Last problem in my form is the field with the following code

                     

                    var Marge = this.getField("Marge").valueAsString;

                    var Tarief = this.getField("Tarief").valueAsString;

                    if (Marge && Tarief) event.value = Number(Marge) / Number(Tarief-Marge);

                    else event.value = "";

                     

                    If non of the fields are filled (so when there is nothing to calculate) it now gives as a result: 0,00%

                     

                    I would like it to be blanc if there is nothing to calculate. I thought the else event.value would do that.

                    • 7. Re: Calculation not working
                      Karl Heinz Kremer Adobe Community Professional

                      Unfortunately you need a bit more to make this work:

                       

                      if (Marge != "" && Tarief != "")

                       

                          event.value = Number(Marge) / Number(Tarief-Marge);

                       

                      else

                       

                           event.value = "";

                      The reason this is not working is that any valid string when cast to a

                      boolean will result in true in JavaScript.

                       

                       

                      Karl Heinz Kremer

                      • 8. Re: Calculation not working
                        George_Johnson MVP & Adobe Community Professional

                        Unfortunately you need a bit more to make this work:

                         

                        if (Marge != "" && Tarief != "")

                         

                            event.value = Number(Marge) / Number(Tarief-Marge);

                         

                        else

                         

                             event.value = "";

                        The reason this is not working is that any valid string when cast to a

                        boolean will result in true in JavaScript.

                         

                         

                        Not if the string has zero length. That part of the original code is fine, but the line that does the calculation should be changed to:

                         

                         

                        event.value = Number(Marge) / (Number(Tarief) - Number(Marge));

                         

                        assuming that's the calculation that's wanted.

                        • 9. Re: Calculation not working
                          gkaiseril MVP & Adobe Community Professional

                          With a format of "Percentage" the displayed value is a string value because of the '%". I have found that to have a null value display, one needs to change the result field to number and then use the "" string. Within a calculation one needs to dynamically change the format within the script. Acrobat has a couple of built-in functions that can provide that type of action. The field should have a format of "None" or "Number".

                           

                          var Marge = this.getField("Marge").valueAsString;
                          var Tarief = this.getField("Tarief").valueAsString;
                          // some formatting options;
                          var nDec = 2; // number of decimal places;
                          var sepStyle = 0; // separator style;
                          var negStyle = 0; // negative style;
                          if ( Marge !="" && Tarief != "" ) {
                          // compute if values not null;
                          event.value = Number(Marge) / (Number(Tarief) -Number(Marge));
                          // format as percentage with formatting options;
                          AFPercent_Format(nDec, sepStyle, negStyle);
                          } else {
                          // format as number with formatting options and populate the value with a null string;
                          AFNumber_Format(nDec, sepStyle, negStyle)
                          event.value = "";
                          }

                          • 10. Re: Calculation not working
                            Angie_74 Level 1

                            Thank you so much.

                            If I change the format of the field to Number, it gives me an error message.

                            but with the field format on None it seems to work perfectly.