Skip to main content
March 16, 2017
Question

Calculating Form Field Totals

  • March 16, 2017
  • 2 replies
  • 398 views

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?

This topic has been closed for replies.

2 replies

Inspiring
March 16, 2017

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.

try67
Community Expert
Community Expert
March 16, 2017

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.

March 16, 2017

Thank you for the quick reply!

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

Thank you!

try67
Community Expert
Community Expert
March 16, 2017

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).valueAsString==answers) {

        totalCorrect++;

    }

}

event.value = (totalCorrect/answers.length).toFixed(2);