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

calculating field in pro dc form

Community Beginner ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

Hello, I have a survey form with 10 questions each with 6 possible answers.  The total score is a percentage.  I have give the radio buttons a value of 0 through to 5.  So if all questions are answered the maximum total would be 50.  My dilema is, some of the questions may not be answered (that would fix the issue but we want to allow them to not answer all questions).  The calculation needs to be based on only the questions answered eg if they do all questions and have a score of 30, my calc would be (30/50)*100  but how do I work it if they only answer 8 questions giving a maximum total of 40; or 7 questions giving max of 35 etc etc

 

Any advice would be appreciated 🙂

TOPICS
How to

Views

517

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 , Aug 30, 2021 Aug 30, 2021

Lets say your radio button groups are named Question1-Question10, you can use this as custom calculation of percentage field:

var total = 0;
var p = 0;
for( var i=1; i<=10; i++){
if(this.getField("Question"+i).value != "Off"){
total+=this.getField("Question"+i).value;
p++;}}
if(total == 0)
event.value = "";
else
event.value = (total/(p*5));

Votes

Translate

Translate
Community Expert ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

Moving thread to the Acrobat forum from Using the Community

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 ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

Lets say your radio button groups are named Question1-Question10, you can use this as custom calculation of percentage field:

var total = 0;
var p = 0;
for( var i=1; i<=10; i++){
if(this.getField("Question"+i).value != "Off"){
total+=this.getField("Question"+i).value;
p++;}}
if(total == 0)
event.value = "";
else
event.value = (total/(p*5));

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 ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

nailed it.  Thank you

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 ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

I'd suggest adding a radio button for "N/A - Unanswered" and then setting a default value for each button as N/A.

 

I created a sample form (attached) that assigns values of 0, 5, and 10.  This also shows the total unanswered questions.  The code for the example below.  I could have looped the code as in the other example, but I just wanted to show a simplified way to figure out what you were asking.

 

var total = 0;
var groupValue = 0;

groupValue = this.getField("Group1").value;

if (groupValue =="0") {
total +=1;
}

groupValue = this.getField("Group2").value;

if (groupValue =="0") {
total +=1;
}

groupValue = this.getField("Group3").value;

if (groupValue =="0") {
total +=1;
}


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
Community Beginner ,
Aug 30, 2021 Aug 30, 2021

Copy link to clipboard

Copied

LATEST

thank you.  I don't have the space on this form to add n/a to each question; however it  is great to learn other options for future use.

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