8 Replies Latest reply on Sep 6, 2012 1:46 AM by zubobinski

    Delay in field calculation appearing

    zubobinski Level 1

      Hi all

       

      Apologies but my coding skills are a bit dated.

       

      I have three fields A,B and C

       

      User puts a number into A and B calculates the value of this multipled by a number using a bit of Javascript

      var field2 = this.getField("CPDNo").value;

      event.value = field2 * 25;

       

      Now C does some checks on the value of B to determine whether to use a minimum value or a maximum value here

      var field1 = this.getField("cpdval").value;

      if (field1<"100"){event.value = "100";

      } else if (field1>"7500"){event.value = "7500";

      } else event.value = field1;

       

      What I find is B is always correctly calculated but C will wait until I click into another field before performing its calculation...

       

      What am I doing wrong here??

       

      thanks

       

      george

        • 1. Re: Delay in field calculation appearing
          MarkWalsh Level 4

          Where have you put the code you are using for each field? Which event are you using?

          • 2. Re: Delay in field calculation appearing
            zubobinski Level 1

            Mark, the field properties final tab is Calculate and I have edited the custom calculated script entry and included the Javascript in there.

            • 3. Re: Delay in field calculation appearing
              gkaiseril MVP & Adobe Community Professional

              Have you verified the field calculation order?

               

              There is a special pop-up window that allows one to order the field calculation by arranging the order the fields with calculations are to be processed.

              • 4. Re: Delay in field calculation appearing
                zubobinski Level 1

                Hi thanks for that - its almost resolved the problem....

                 

                I have 7 calculated fields and have now set the order ... all is fine except for last two fields, the actual sequence is

                 

                A    B=A * a value   C=value depends on B

                D     E=D * a value  F=value depends on E

                G    H=G * a value  I=value depends on H

                 

                Totlal Value field J= sum of C, F, I

                 

                and because I doesnt recalc, J remains the same - so my problem I think is only with I

                 

                Note that G is the last field which requires data to be entered, not sure if that is the problem. since H recalcs ok

                Note also that BE and H are read only and required...

                 

                george

                • 5. Re: Delay in field calculation appearing
                  George_Johnson MVP & Adobe Community Professional

                  You should post the script you're using for J.

                  • 6. Re: Delay in field calculation appearing
                    zubobinski Level 1

                    I script is

                    var field3 = this.getField("mcsval").value;

                    if (field3<"100"){event.value = "100";

                    } else if (field3>"7500"){event.value = "7500";

                    } else event.value = field3;

                     

                    j is not a script its the first section in calculate tab - Value is the sum(+) of C,F,I

                    • 7. Re: Delay in field calculation appearing
                      gkaiseril MVP & Adobe Community Professional

                      If the contents of the field mscval is a number you should not be comparing it to string value.

                       

                      Are you getting any errors in Acrobat's JavaScript console?

                       

                      Are you sure your comparisons are in the correct order for what you are trying to accomplish?

                       

                      I would have coded this as follows:

                       

                      var field3 = this.getField("mcsval").value;

                      // default value

                      event.value = field3;

                      if (field3 < 100) {

                      // field3 less than 100

                      event.value = 100;

                      } else if (field3 > 7500){

                      // field2 greater than 7500

                      event.value = 500;

                      }

                       

                      or

                       

                      var field3 = this.getField("mcsval").value;
                      switch(true) {
                      // field3 is less than 100
                      case (field3 < 100) :
                      event.value = 100;
                      break;

                      // field3 is greater than > 7500
                      case (field3 > 7500) :
                      event.value = 500;
                      break;

                      // all other values
                      default:
                      event.value = field3;
                      break;
                      }

                      1 person found this helpful
                      • 8. Re: Delay in field calculation appearing
                        zubobinski Level 1

                        thanks, nice to see the case example, much neater.

                         

                        Not sure how Acrobat handles numeric values in text ... doesn't seem to care or make any difference.

                         

                        Interestingly, its only the preview mode of Acrobat Pro where the field does not get calculated if I I use a clients reader it calculates fine.

                         

                        Also in Pro, I have added another page onto my form, if I move onto the next page, the read only value field does the calculation, so I suspect that until focus leaves the field to another required field calculations do not occur.... just my observations for what they are worth!

                         

                         

                         

                        george