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

Calculate the Totals of Yes, No, and NA of grouped Radio Buttons using JavaScript

New Here ,
Sep 07, 2022 Sep 07, 2022

Copy link to clipboard

Copied

I have searched the posts and tried the code, but I am missing something.

 

My Grouped Radio Buttons have JavaScript on Mouse Down

this.getField("Yes").value = "1"

this.getField("No").value = "2"

this.getField("NA").value = "3"

 

My Text Fields has JavaScript for Custom calculation script. The Yes and 1 are changed to No and 2, and NA and 3 for their respective text field.

(function () {

var i, val, sum = 0;

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

val = getField("Group" + i).getField("Yes").value; 

if (val == "1") {

sum += +val;

}

}

event.value = sum;

})();

TOPICS
JavaScript , PDF forms

Views

431

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

If your fields are named "Group1-48" and their choices are "Yes" "No" and "NA", you can use this as custom calculation script of "Yes" field:

var total = 0;
for(var i=1; i<=48; i++){
if(this.getField("Group"+i).valueAsString == "Yes")
total++;}
event.value = total;

 

For other fields, just change "Yes" to "No" or "NA".

Votes

Translate

Translate
Adobe Employee ,
Sep 07, 2022 Sep 07, 2022

Copy link to clipboard

Copied

Hi @glstephens08,

 

Hope you are doing well. Per the description, I understand that you want to calculate the value for radio buttons.

 

You may refer to the given link to get the complete script for the calculation:

Calculate radio buttons | Adobe Acrobat (acrobatusers.com)

 

Hope this helps.

 

-Souvik.

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

Copy link to clipboard

Copied

Following line makes no sense:

val = getField("Group"+i).getField("Yes").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 ,
Sep 07, 2022 Sep 07, 2022

Copy link to clipboard

Copied

I tried it as val = getField("Group"+i).value; and that didn't work either

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

Copy link to clipboard

Copied

If your fields are named "Group1-48" and their choices are "Yes" "No" and "NA", you can use this as custom calculation script of "Yes" field:

var total = 0;
for(var i=1; i<=48; i++){
if(this.getField("Group"+i).valueAsString == "Yes")
total++;}
event.value = total;

 

For other fields, just change "Yes" to "No" or "NA".

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

Copy link to clipboard

Copied

LATEST

Thank you that worked.

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