Skip to main content
Mar 16, 2017 1:14 AM UTC
Question

Calculating Form Field Totals

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 is closed to new replies. Start a new post to keep the conversation going.

4 replies

Inspiring
Mar 16, 2017 4:05 PM UTC

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.

Translate
try67
Community Expert
Community Expert
Mar 16, 2017 8:55 AM UTC

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.

Translate
Mar 16, 2017 1:04 PM UTC

Thank you for the quick reply!

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

Thank you!

Translate
try67
Community Expert
Community Expert
Mar 16, 2017 1:12 PM UTC

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);

Translate