6 Replies Latest reply on May 9, 2013 5:37 PM by Beaster1

    Total field calculation

    Beaster1

      I am trying create a script that adds to a total field  for both correct and incorrect responses based on the color of the text. For instance the incorrect reponse turns RED   the correct response is BLACK.  I will like to have a running total of both response.

      EXAMPLE    

       

      Header 1Header 2Header 3Header 4
      Q 1        AQ 2    C Q 3    AQ 4      A
      Q 5      BQ 6     AQ 7      DQ 8      D
      Q 9      CQ 10  BQ 11    CQ 12   D
      Q 13    AQ 14   D# WRONG   3# CORRECT  11
        • 1. Re: Total field calculation
          try67 MVP & Adobe Community Professional

          You'll need to use a custom script to go over all of the fields, checking their textColor property and based on their color decide whether or not use them in your calculation.

          If you provide the field names I could help you with the code.

          • 2. Re: Total field calculation
            Beaster1 Level 1

            The field where the user places their response are called Quest 1 thru Quest 20 and the total count fields names are T-Wrong and T-correct. Thanks...

            • 3. Re: Total field calculation
              try67 MVP & Adobe Community Professional

              Custom calculation for T-Wrong:

               

              var total = 0;

              for (var i=1; i<=20; i++) {

                   var f = this.getField("Quest "+i);

                   if (color.equal(f.textColor, color.red))

                        total++;

              }

              event.value = total;

               

              And for T-correct:

              var total = 0;

              for (var i=1; i<=20; i++) {

                   var f = this.getField("Quest "+i);

                   if (color.equal(f.textColor, color.black))

                        total++;

              }

              event.value = total;

              • 4. Re: Total field calculation
                Beaster1 Level 1

                Hi

                Your code is good. The only problem that I am running is the following:

                (1) the T-Wrong counter count down ( is that how it works?)

                (2) the  two counter will not work if the variable is change to 30 or more.

                THANKS

                • 5. Re: Total field calculation
                  try67 MVP & Adobe Community Professional

                  1) Not sure what you mean...

                   

                  2) There isn't a limit to the number of fields that you can process. If it stops working after a certain number there's most likely an error in the name of one of the fields you specified. Check the JS console (Ctrl+J) for any error messages.

                  • 6. Re: Total field calculation
                    Beaster1 Level 1

                    Found the problem in field 31. The number one (1) was transposed as capital (I).. Problem solved.. Again THANKS..