Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you for the quick reply!
I am not familiar with creating arrays. Could you please elaborate? Or perhaps provide a procedure?
Thank you!
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now