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

Calculation to score a quiz with radio buttons?

New Here ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

I have a 10 question multiple choice quiz that uses radio buttons to select the answer. There are no right or wrong answers, but each answer is assigned a certain number of points. For example, with question 1, an answer of A = 0, B = 4, C = 8, D = 16, E = 20. I'd like to create a calculation that will add up the score from all 10 questions.

 

Desired answer values:

1. A=0, B=4, C=8, D=16, E=20

2. A=0, B=1, C=2, D=3, E=5

3. A=0, B=4, C=8, D=12, E=20

4. A=0, B=2, C=3, D=5

5. A=0, B=4, C=6, D=10

6. A=0, B=2, C=3, D=4, E=5

7. A=0, B=2, C=8, D=10

8. A=0, B=2, C=6, D=10

9. A=0, B=4, C=6, D=8, E=10

10. A=0, B=2, C=3, D=4, E=5

 

Radio buttons are grouped by question (Question 1, Question 2, etc) and are named choice1, choice2, etc. Screenshots of form are below. I want to tally all of this into one field. Any suggestions?

Quiz Page 1.PNGQuiz Page 2.PNG

 

TOPICS
Create PDFs , Edit and convert PDFs , How to , PDF forms

Views

4.7K

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Nov 05, 2020 Nov 05, 2020

Instead of choice1,choice2 name them points value e.g. 0,4,8,16,20 do that for all buttons then in properties of field where you want to show result, in  "calculate" tab go to "Value is the" and pick your buttons groups.

Votes

Translate

Translate
Enthusiast , Nov 06, 2020 Nov 06, 2020

I don't get why you guys complicate it so much, he don't need any script just give groups a choice of points ,

First group of radio buttons named "Question1" and choice for A answer is 0 choice for B answer is 4...etc and just use value is the in total field.

Votes

Translate

Translate
Community Expert ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

Instead of choice1,choice2 name them points value e.g. 0,4,8,16,20 do that for all buttons then in properties of field where you want to show result, in  "calculate" tab go to "Value is the" and pick your buttons groups.

Votes

Translate

Translate

Report

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 ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

Your scoring system is not a good one. It doesn't allow you to distinguish between questions that were answered A, and questions that were not answered at all, as in both scenarios it will add zero to the total sum...

Votes

Translate

Translate

Report

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 ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

There are many ways to do this with Acrobat JavaScript, but I think that the easiest way to grasp the concept of adding export values taken from different groups of radio buttons  is to name your radio button fields in a hierarchy fashion. Like for example, "Group.1", "Group.2", "Group.3", "Group.4", and so on.

 

In my example below I did two rows of 5 radio buttons, but I named all radio buttons in the first group with the same name and assigned to each one a different export value (taken from your example table above)  to make them mutually exclusive.

 

radiobuttons.png

 

In my first set of radio buttons all of them are named "Group.1" and in the other set they are all named "Group.2".

 

Doing this allows to use the code shown below in a very easy way to add up all the values. 

 

So, in the text field that you want to show the total use the following calculation script:

 

 

var f = this.getField("Group.");
var a = f.getArray();
var v = 0.0;

for (i =0; i < a.length; i++)  v += a[i].value;

event.value = v;

 

 

The only problem with this, is that I haven't been able to figure out how to make the total field null when the radio buttons are reset. I can't figure out how to not make the value "Off" not to be counted by the script.

Votes

Translate

Translate

Report

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
Enthusiast ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

I don't get why you guys complicate it so much, he don't need any script just give groups a choice of points ,

First group of radio buttons named "Question1" and choice for A answer is 0 choice for B answer is 4...etc and just use value is the in total field.

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

The complication is not on our end.

 

The complication is what the user asks here:

 

I'd like to create a calculation that will add up the score from all 10 questions.

 

Desired answer values:

1. A=0, B=4, C=8, D=16, E=20

2. A=0, B=1, C=2, D=3, E=5

3. A=0, B=4, C=8, D=12, E=20

4. A=0, B=2, C=3, D=5

5. A=0, B=4, C=6, D=10

6. A=0, B=2, C=3, D=4, E=5

7. A=0, B=2, C=8, D=10

8. A=0, B=2, C=6, D=10

9. A=0, B=4, C=6, D=8, E=10

10. A=0, B=2, C=3, D=4, E=5

 

 

The OP asked for a calculation that will add all scores,

 

The script that I posted above is the simplest form but tge user is employing mutually exclusive radio buttons but to make them mutually exclusive the score values should be used as export values, like NesaNurani suggested.

 

So in short, the calculation script that OP  is asking for should add up all the export values of all radio buttons.

 

 

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

And when a radio button is reset or unchecked, the export value of that radio button becomes "Off" by default.

 

This is the part that doesn't make it simple. If you add all the values of the radio buttons like you're saying, you'll get  something like this:

 

20Off4OffOff instead of 24 for example.

 

So if it is not that complicated to you, why don't you share the piece of your code here.

 

Just remember, the user asked to calculate 10 questions, but each question has 5 choices, that means you need to calculated 50 possible choices based on the checked or unchecked state of each radio buttons per question.

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

are you even testing on your end the suggestions that you're recommending before you post an comment?

 

Are you even caring to check for errors before you suggest a solution Asim?

Votes

Translate

Translate

Report

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
Enthusiast ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Here  is my example. So whats wrong with it?

Votes

Translate

Translate

Report

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
Explorer ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

I had the same solution unless Timothy wants to exclude the unanswered questions from the sum.  

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

What I'm trying to say is not what is wring with your solution. What I am pointing out is when you uncheck the reset the buttons. 

 

Radio buttons remain checked the entire time, and need an button or a checkbox to reset their checked state to unchecked.

 

Unless I don't understand what you guys are trying to say, I think you're treating this exercise as if these radio buttons are checkboxes.

 

And if the OP doesn't care about having answers selected permanently in that form (without resetting the radio buttons), then of course your solution works.

 

Are you saying that when you uncheck a radio button the sum  doesn't reveal  Off20Off (or similar)

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Disregard all my examples and everything I've said, which created too much confusion.

 

Asim is right and actually proved the correct answer.

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Thank you for pointing that out. 

 

You were right, we are complicated this too much.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

Do you want questions that are not answered to be excluded from the calculation or to default to 0?

Votes

Translate

Translate

Report

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 ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

I didn't think of that, yes.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Yes, you want it to be excluded or, yes, you want the default value to be zero.  If you want the default value to be zero then I would suggest following Nesa Nurani's solution provided above.  Here are more detailed actions:

  • Select the Options tab from the Properties dialog box for each of the radio buttons
  • Update the Radio Button Choice to correspond with the point value for each of the answers (Ex:  set Radio Button Choice for  A to 0, B to 4, C to 8, D to 16, and E to 20)
  • Repeat this for each question and corresponding radion buttons
  • Create a text field and format it as a number to sum the values, then select the Calculate tab from the Properties dialog box
  • Select "Value is the" radio button and "(sum+)" from the dropdown menu, then click the "Pick" button and check the boxes of the 10 questions you want to sum

 

Hope this helps!

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

BASICS, 

 

Thank you for your inut . I am still taking your idea for one form that I'm working on.

 

I don't want the 0 to show when no radio buttons are selected.

Votes

Translate

Translate

Report

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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Never mind, 

 

I used Asims's file example and added a custom format script to take care of the 0 value when no radio buttons are selected:

 

var v = this.getField("Text2").valueAsString;

if (v <=0) event.value ="";

Votes

Translate

Translate

Report

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
New Here ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

Hi, I am trying to accomplish a similar concept but for each question I want the value to populate and then I want a total score to add up those values. 

 

So, I am trying to have the user select from 10 questions each with 4 button choices that hold values (2.5,5,7.5,10). Next to each question, I have a "value" box to show what they selected for that question. Then at the bottom of the page there is a "Total Score" where I would like the "sum" of all of the respective values to populate.

 

Right now I just type in the value that corresponds to the selected button and add them myself for the Total Score where I type in the Total... Not productive. Lol.

 

Is this possible?

 

Thanks in advance!

Votes

Translate

Translate

Report

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 ,
Jul 27, 2021 Jul 27, 2021

Copy link to clipboard

Copied

Apply those values as the "radio-button choice" of each field (under Properties - Options) in the radio-button group, and then you could use a simple script to copy that group's value to the text field, which can in turn be summed using the built-in Sum command under the Calculate tab of your Total Score field.

The script to use would be something like this (let's say the first group of radio-buttons is called "Q1"):

 

var v = this.getField("Q1").valueAsString;

event.value = (v=="Off") ? "" : v;

Votes

Translate

Translate

Report

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 Beginner ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Hi thanks for the java script. To add multiple check boxes do I copy the code below and change Q1 to Q2

Votes

Translate

Translate

Report

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 ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

You mean you want to make the condition based on more than one check-box? What should happen if both boxes are ticked? Which value(s) should it show?

 

Votes

Translate

Translate

Report

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 Beginner ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

Hi Try67, thank you for responding it's very much appreciated.

I have a series of 10 multi-choice questions (approx 5 possible answers to each question); each answer has an increasing value from 1, to a maximum of 5. (I have these values stored button choice) and I wish to add the questions on each page with a sub-total, and then at the end a total of the sub-totals to give a final score. 

 

I am also happy to pay you if you wish to do the work, as I am a Financial Adviser and Adobe is not a skill set of mine.

Votes

Translate

Translate

Report

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 ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

LATEST

Feel free to contact me privately (click my user-name and then on "Send a message") to discuss it further.

Votes

Translate

Translate

Report

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
New Here ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Thank you all. This was super helpful and got me where I needed to be.

Votes

Translate

Translate

Report

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