Skip to main content
Inspiring
December 14, 2016
Answered

How to calculate cumulative marks in a pdf field?

  • December 14, 2016
  • 5 replies
  • 1539 views

I prepare a question paper in acrobat pro. Each ques has check box for correct & incorrect answer. It has a totalmarks field & each quesmark field. What I am trying to do, when a person ticks correct answer check box of any ques then his/her cumulative marks will show in total marks field. I want to implement this for all 10 question of my paper.

Can anybody please help?

This topic has been closed for replies.
Correct answer try67

OK, then you can use this script as the custom calculation of the total marks field:

var totalCorrect = 0;

for (var i=1; i<=10; i++) {

    if (this.getField("correctq"+i).value!="Off") totalCorrect++;

}

event.value = Number(this.getField("questionmark").value) * totalCorrect;

5 replies

jahantechAuthor
Inspiring
December 19, 2016

Thanks for the reply.

It perfectly works for me. Thanks again.

jahantechAuthor
Inspiring
December 18, 2016

Thanks for reply.

WhenI try, it shows SyntaxError:illegal character3:at line 4.

When I use below code

var totalCorrect = 0;

for (var i=1; i<=10; i++) {

    if (this.getField("correctq"+i).value!="Off") totalCorrect++;

}

event.value =

Number((this.getField("questionmark").value) * totalCorrect);

No error shows. In this case if I check or uncheck any checkbox no change in "totalmarks" field whether I change "questionmark" fields value then "totalmarks" fields value changes.

Rgds

try67
Community Expert
Community Expert
December 18, 2016

Works just fine for me. Did you copy the code into Word or something like that?

try67
Community Expert
Community Expert
December 18, 2016

Press Ctrl+J and see if there are any error messages there.

jahantechAuthor
Inspiring
December 18, 2016

Thanks for the reply

For correct question I have check boxes named (“correctq1”, “correctq2”, “correctq3”, “correctq4”, “correctq5”, “correctq6”, “correctq7”, “correctq8”, “correctq9”, “correctq10”)

For incorrect question I have ckeck boxes named (“incorrectq1”, “incorrectq2”, “incorrectq3”, “incorrectq4”, “incorrectq5”, “incorrectq6”, “incorrectq7”, “incorrectq8”, “incorrectq9”, “incorrectq10”)

For all questions I have only one “questionmark” field.

Rgds

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 18, 2016

OK, then you can use this script as the custom calculation of the total marks field:

var totalCorrect = 0;

for (var i=1; i<=10; i++) {

    if (this.getField("correctq"+i).value!="Off") totalCorrect++;

}

event.value = Number(this.getField("questionmark").value) * totalCorrect;

jahantechAuthor
Inspiring
December 14, 2016

Thanks for reply.

I have two check-boxes named "correct" & "incorrect" for each question. Other field are "questionmark" & "totalmarks". From which user will select one of them. If user select "correct" field then it would be "correct" * "questionmark" and result will populate in total marks field.

rgds

try67
Community Expert
Community Expert
December 14, 2016

So there's a single "questionmark" field, or one for each question?

Also, you still didn't specify what are the names of the check-box fields...

try67
Community Expert
Community Expert
December 14, 2016

Your description is not very clear... Do you have a check-box that says whether or not the question was answered correctly, or do you have multiple check-boxes which are the answers for the question, and the user selects one of them?

Also, what are the names of the fields involved?