Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculating Form Field Totals

Guest
Mar 15, 2017 Mar 15, 2017

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?

TOPICS
Acrobat SDK and JavaScript
367
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2017 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 16, 2017 Mar 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2017 Mar 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 16, 2017 Mar 16, 2017
LATEST

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines