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

Is there a script to calculate a total based on a radio button choice

Participant ,
Jun 19, 2023 Jun 19, 2023

I would like to calculated the amount based on the choice selected. Is this possible?

 

Start amount 1

 

Start amount 2

 

4 questions with 2 answers each 

Q1 = random amount; choice 1 or 2

Q2 = random amount; choice 1 or 2

Q3 = random amount; choice 1 or 2

Q4 = random amount; choice 1 or 2

Q5 = random amount; choice 1 or 2

Q6 = random amount; choice 1 or 2

Q7 = random amount; choice 1 or 2

Q8 = random amount; choice 1 or 2

Q9 = random amount; choice 1 or 2

Q10 = random amount; choice 1 or 2

Q11 = random amount; choice 1 or 2

Q12 = random amount; choice 1 or 2

Q13 = random amount; choice 1 or 2

Q14 = random amount; choice 1 or 2

Q15 = random amount; choice 1 or 2

 

End amount 1 = start amount 1 - sum amount for all questions with choice 1

 

End amount 2 = start amount 2 - sum amount for all questions with choice 2

TOPICS
JavaScript , PDF , PDF forms
510
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 ,
Jun 19, 2023 Jun 19, 2023

I'm not sure what are start and end amounts, but to calculate total choices you can do it like this:

var c1 = 0;
var c2 = 0;
for( var i=1; i<=15; i++){
var RB = this.getField("Q"+i).valueAsString;
if(RB === "Choice1")c1++;
if(RB === "Choice2")c2++;}

Variable c1 contains total for 'Choice1" and c2 contains total for "Choice2" use them in further calculations that you want.

 

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
Participant ,
Jun 19, 2023 Jun 19, 2023

ex.png

I didn't quite understand how I could make that work with what I have.  This is what I am aiming for.  Can you provide a little more detail based on this? Thank you

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 ,
Jun 19, 2023 Jun 19, 2023

Can you show an image from 'Prepare form' where you can see field names, or even better, share your file?

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
Participant ,
Jun 20, 2023 Jun 20, 2023
LATEST

I sent you a link to the document if that is okay. 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