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

Calculating Radio Button Multiple Choices

Community Beginner ,
Jan 26, 2024 Jan 26, 2024

Hi Acrobat Community... I am developing a project criteria form that will need to calculate the choices made to provide a project assessment. There are three choices per line. If I calculate using 'Value is the sum (+)' it works—if there is only one choice, but since there are three, I need to calculate them individually.  And when I do this for each choice's summary text frame, I get a combined calculation (see attachment).  If there are 3 E's, that number needs to be shown.

I think that I will need a 'Simplified field notation' script to help, but I don't know how to create scripts. I did see this post, but I don't know if it will work or how to modify it to fit my needs. 

Attached is a screenshot to give context. Each category line radio buttons have the same name. Line one's name is "1 History" line two is "1 Problems", etc. and the user can select either E, A, or N. In the end, there will be 9 different categories, but for now, I'm just testing one to see if doable to do the calculations.

I hope that I am cleary, but if not, please ask questions if you need further clarity. Thanks in advance!!

49a101ad-1e84-46c7-bf38-8ec8e27db8fb.png

radio button choices.PNG

TOPICS
JavaScript , PDF , PDF forms
1.5K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 26, 2024 Jan 26, 2024

Use this as custom calculation script in one of the text fields:

 

 

var fields = ["1 History", "1 Problems"];// add all radio button field names here
var e = 0, a = 0, n = 0;

for ( var i in fields){
 if(this.getField(fields[i]).valueAsString === "Choice1")e++;
 else if(this.getField(fields[i]).valueAsString === "Choice2")a++;
 else if(this.getField(fields[i]).valueAsString === "Choice3")n++;}

this.getField("E Total").value = e;
this.getField("A Total").value = a;
this.getField("N Total").value = n;

 

 

View solution in original post

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 ,
Jan 26, 2024 Jan 26, 2024

Use this as custom calculation script in one of the text fields:

 

 

var fields = ["1 History", "1 Problems"];// add all radio button field names here
var e = 0, a = 0, n = 0;

for ( var i in fields){
 if(this.getField(fields[i]).valueAsString === "Choice1")e++;
 else if(this.getField(fields[i]).valueAsString === "Choice2")a++;
 else if(this.getField(fields[i]).valueAsString === "Choice3")n++;}

this.getField("E Total").value = e;
this.getField("A Total").value = a;
this.getField("N Total").value = n;

 

 

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 Beginner ,
Jan 26, 2024 Jan 26, 2024

Thank you... I'll take a look and see if this works. Clarity question: Since I need to calculate all the E's, A's, and N's individually, would I need to add this same script for all 3 text frames? So, in the example screenshot that was provided earlier, in each place that the number 11 is showing, they are 3 different text frames with the same calculated property info value. But I'm sure I need to provide different script info to make them total correctly. Thanks

button (edit) screenshot.PNG

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 ,
Jan 26, 2024 Jan 26, 2024

No, just put script in one field (any text field is fine).

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 Beginner ,
Jan 26, 2024 Jan 26, 2024

Thanks... forgive me, but I'm still not understanding. See the next round of screenshots to be sure I'm clear. How can I achieve a total for each if I only place the script in one text frame? Also, when you speak of "field" is that changing the Choice 1 to E and Choice2 to N, etc.?

script placement.PNGvalues-fields.PNG

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 ,
Jan 26, 2024 Jan 26, 2024

Leave choices as 'Choice1', 'Choice2' and 'Choice3'.

Script will put totals in all 3 fields.

In the script, you didn't change field names to your actual names.

Field name is not "E" your actual name is "E Total", I updated script so it includes correct field names, use updated script or change field names manually.

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 Beginner ,
Jan 26, 2024 Jan 26, 2024

Thanks, Nesa... I inserted the new script but it still doesn't work. I was going to upload the actual PDF, but I cannot. When I click any of the buttons, no total amount appears. 

script placement_rev.PNG

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 Beginner ,
Feb 05, 2024 Feb 05, 2024
LATEST

Thank you again, Nesa!! I have completed this project with all "fields" added and the Total calculations' text frames are displaying correctly. Hopefully, I'll be able to use this on other similar projects. 

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 ,
Jan 26, 2024 Jan 26, 2024

Do you mean that you want to count the number of times "E" was selected, for example?

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 Beginner ,
Jan 26, 2024 Jan 26, 2024

Correct. Once that particular project assessment is completed (all 9 categories), they would like to see the total of  E's (excellent), A's (average), etc. it has received. Thanks

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