8 Replies Latest reply on Dec 3, 2013 4:20 AM by Angie_74

    Help needed with calculations in pdf file please

    Angie_74

      I would appreciate help with some calculations.

      I have field A, B, C and D. In field A and B one will fill out numbers. Field C is a calculated field (A-B). So far this works for me.

      However if field B is blank for example, field C will show the value of field A. If field B is blank I would like field C also to be blank. I got as far as thinking I need to put something in the validation tab of field C, but what I need to put I do not know.

       

      Further more I need to calculate a % in field D. The value of field C in a % of field B. With this one I'm drawing a total blank. With this one also goes if field C is empty, field B also should be empty.

      I hope there is someone out there that can help.

       

      Thank you in advance

        • 1. Re: Help needed with calculations in pdf file please
          Test Screen Name Most Valuable Participant

          No, it isn't a validation you need. That is to control what someone is allowed to type. You need instead to have a calculation which checks the input values (A and B) and sets the output value (C) to blank if either one is blank, only then carrying on to do the calculation.

          • 2. Re: Help needed with calculations in pdf file please
            Angie_74 Level 1

            ok, thank you, will forget about the validation part then. Any thoughts on the correct calculation. My knowledge stops at excel formulas and they dont seem to work in here or maybe I should say I do not know how to implement them in pdf.

            • 3. Re: Help needed with calculations in pdf file please
              try67 MVP & Adobe Community Professional

              As mentioned, this needs to be a custom calculation of field C. You can use something like this:

               

              var a = this.getField("A").valueAsString;

              var b = this.getField("B").valueAsString;

              if (a && b) event.value = Number(a) - Number(b);

              else event.value = "";

               

               

              Your question about field D is not very clear... If you want it to be 20% of field C, for example, you can use this custom calculation script:

               

              var c = this.getField("C").valueAsString;

              if (c) event.value = Number(c) * 0.2;

              else event.value = "";

              • 4. Re: Help needed with calculations in pdf file please
                Angie_74 Level 1

                Thank you, I will try this in a minute

                With regards to field D. If for example A (100) - B (80) = C (20).

                Field D would then need to calculate C (20) / B (80) = D (25%)

                • 5. Re: Help needed with calculations in pdf file please
                  try67 MVP & Adobe Community Professional

                  OK, so for field D use this code, and set the field as a Percentage field under Format:

                   

                  var b = this.getField("B").valueAsString;

                  var c = this.getField("C").valueAsString;

                  if (b && c && Number(b)!=0) event.value = Number(c) / Number(b);

                  else event.value = "";

                  • 6. Re: Help needed with calculations in pdf file please
                    gkaiseril MVP & Adobe Community Professional

                    Will field "B" ever have a value of zero?

                     

                    Assuming fields "B" and "B" are formatted as "Number" and field "A" is  formatted as "Percentage", then only only needs to check for field c for a value of zero.

                     

                    One may also need to account for the fact that a null string ("') field will be treated as zero.

                     

                    The custom calculation for field "D" could be:

                     

                    // get field objects;

                    var oDivisor = this.getField("B"); // field object for divisor;

                    var oDividend = this.getField("C"); // field object for dividend;

                    event.value = ""; // default result if no computation performed;

                    if(oDivisor.value != 0 && oDividend.value != 0) {

                    event.value = oDividend.value / oDivisor.value;

                    }

                    • 7. Re: Help needed with calculations in pdf file please
                      Angie_74 Level 1

                      Thanks everyone for the help. Stupidly enough i discarded something and now my whole form is messed up and I need to restart

                      Fields A, B and C will be formatted as Number. And field D as Percentage.

                      And yes, field B could be blanc

                      • 8. Re: Help needed with calculations in pdf file please
                        Angie_74 Level 1

                        Thank you again for your help. I have an additional question. The part with the % I am going to forget about. Since it is simply not possible the way I want it. Or at least I cannot get it to work the way I want it. If someone here would like to try work with me on it, it would be appreciated however

                         

                        My additional question for now is that I have a field that simply states the value from another field. If I delete the value of the original field, the 2nd field does not update and keeps the old value instead of also going blanc.