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

calculating radio buttons

New Here ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

Help with radio buttons. I need to calculate a specific button in a given group/row.

I have a form with radio buttons. I've roughly set the radio buttons in for now. I need to have each column total Random, Informal, Formal and Dynamic. So only one radio button selected from each horizontal row 1, 2a, 2b etc.

I'm guessing it has something to do with scripting which I'm not very familiar with.

Form-Example.png

TOPICS
Acrobat SDK and JavaScript

Views

4.4K

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 1 Correct answer

Community Expert , Apr 08, 2018 Apr 08, 2018

Let's say there are five groups and you want to count in how many of them the value "1" is selected.

Use this code as the custom calculation script of the total field:

var total = 0;

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

    var f = this.getField("Group "+i);

    if (f.valueAsString=="1") total++;

}

event.value = total;

Votes

Translate

Translate
Community Expert ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

What are the names of the radio-button groups, and are the export values the same in each group?

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

The radio button  are Group 1 2, 3 etc. and value of just 1 per checkbox or radio button selection. Plus Choice 1, 2, 3, 4. I'm very new to scripting so is it possible to write one out and I can apply one to my document?

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Let's say there are five groups and you want to count in how many of them the value "1" is selected.

Use this code as the custom calculation script of the total field:

var total = 0;

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

    var f = this.getField("Group "+i);

    if (f.valueAsString=="1") total++;

}

event.value = total;

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Thank you so much!!!!

I have it working now...I will refine the entire document and will be back with a few additional questions. Example once the participant completes the survey we want to total the score which I can now do. Plus with the highest total we want a  definition to reveal and explain why and what they are the strongest in the area the totaled the highest in.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Do you mean the highest value from all the totals?

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

So from the four categories Random, Informal, Formal and Dynamic they will be the highest in one of these once complete. From that we have a definition for each category we will reveal. We would prefer to not show all 4 definition just they 1 they scored the highest in.

Currently the form has 13 questions, for the help post I used just 5. I'm hoping the have on a separate page the total score and reveal the definition of the 1 category they scored the highest in.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Do you have the definition text for each category in a text 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
New Here ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

So its not working completely as I need it. Random, Informal, Formal and Dynamic each column need its one total calculated from the 13 questions. As you see below the 4 columns/categories total the same amount, I'm guessing somewhere I need to target/callout the total box.

Form-Example2.png

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

I'll need to see the actual file to be able to help you further.

You can share it via Dropbox, Google Drive, Adobe Cloud, etc.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

All of your radio-buttons have the same export value ("Radio button choice"). You need to give each one in the group a unique value for it to work.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

OK so I've adjusted that but they all track the same value in each total box at the bottom. I need the total box depending on which single choice is selected in each column to track differently. Ultimately when finished only one Colum will have a larger total score.

Do I need to have some type of coding in each total text field? Right now I just have each Group of radio buttons targeted.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

You didn't apply the code I provided in the file you attached earlier. Did you do it now?

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

I placed that code in the Radio Buttons and it worked for just the one total score text box. Should of I placed that code just in the Bottom text box for the score? Currently I have it in both the Radio buttons and in the total text box at the bottom.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

As I wrote, it should be used as the custom calculation script of the text field where you want the result to appear.

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

http://https://pcdhc.box.com/s/v2a1ev1hfwhgntauiq5wzzrxznfsm529

I've uploaded a new file and its working but still just seems to track to all results to the same total. I need each column to track the one radio button choice per question.

I truly apologize and thank you for you time. I'm very new to scripting and my need to review more help me documents. I'm sure this is all user error.  :  )

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

It doesn't seem you applied any of the changes I described. I can't help you further, unless you want me to do it for you, for a fee.

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

Copy link to clipboard

Copied

I have a question related to this thread.

 

I have a row with 3 radio buttons [checkY.group 1, checkN.group 1, checkZ.group 1] grouped to "Group 1"

and the same for 24 more rows. I cant group them in columns since only one radio button needs to be active.

 

Now I want to count all selected "checkY.group x" buttons, so my guess is there should be a way to just read all "checkY" buttons but it does not work like checkboxes. They can't be summarized for some reason. MAybe beacause they are inside a group?

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

Copy link to clipboard

Copied

LATEST

ahh I got it solved with this tutorial blog

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
LEGEND ,
Apr 07, 2018 Apr 07, 2018

Copy link to clipboard

Copied

You should have the radio button in each row in the same exclusionary group and each button has a unique export value. This will result in at most only one item selected in a row. Note you will not be able to unselect a button in a row by clicking on it, you will need a some additional scripting to do that.

Acrobat PDF count dropdown choices

has some possible coding to count the selected radio buttons selected in each column.

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