4 Replies Latest reply on Mar 16, 2017 9:05 AM by gkaiseril

    Calculating Form Field Totals

    rockface82

      I have a PDF form that has numerous fillable form fields.  I am using a validation script that will turn the field red if an incorrect answer is entered into the field.  I would like to be able to calculate the accuracy of the form using a java script or some other function.

       

      Ultimately, I would like to be able to arrive at an accuracy rate of Correct Fields vs. Total # of fields.

       

      I also have some text fields that I would like to omit from this calculation (fields that contain instructions, for example).

       

      Any recommendations?

        • 1. Re: Calculating Form Field Totals
          try67 MVP & Adobe Community Professional

          You can compile an array with the names of fields to check, and the correct answer for each one.

          Then iterate over that array, checking if the current value of each field equals the correct one. If so, increment the value of a counter.

          At the end you'll have the number of correct answers, which you can divide by the length of the array to get a score.

          • 2. Re: Calculating Form Field Totals
            rockface82 Level 1

            Thank you for the quick reply!

             

            I am not familiar with creating arrays.  Could you please elaborate?  Or perhaps provide a procedure?

             

            Thank you!

            • 3. Re: Calculating Form Field Totals
              try67 MVP & Adobe Community Professional

              Here's a simple example. You would use it as the custom calculation script of the score field:

               

              var fields = ["A1", "A2", "A3"]; // Holds the names of the answer fields
              var answers = ["5", "9", "4"]; // Holds the correct answer for each field
              
              var totalCorrect = 0;
              for (var i=0; i<fields.length; i++) {
                  if (this.getField(fields[i]).valueAsString==answers[i]) {
                      totalCorrect++;
                  }
              }
              event.value = (totalCorrect/answers.length).toFixed(2);
              
              • 4. Re: Calculating Form Field Totals
                gkaiseril MVP & Adobe Community Professional

                You might want to look at AcroTex by D.P. Story for a package that can create exams and score them. Many of the examples have full working scripts that cover a lot of the things that must happen for an exam.