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

Assign numerical values to radio dials

Community Beginner ,
Nov 07, 2018 Nov 07, 2018

I have a section of Yes/No radio dials. Each of these dials needs to equal a numerical value for calculating a score for example:

Do you like the color red?

-Yes (3 points)

-No (3 points)

Do you like ice cream?

-Yes (1 point)

-No (1 point)

(Each question holds a different numerical value for calculating a score)

The Yes and No radio dials equal the same number for each individual question; however, each question has its own value. I need to assign values to the Yes and No radio dials so that I can total them by their answers of Yes or No based on their assigned values.

Is there any script to do this or is there a simple setting I'm missing to accomplish this? Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows
2.2K
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

correct answers 1 Correct answer

Community Expert , Nov 15, 2018 Nov 15, 2018

The problem is with the script for TOTAL_RISK_SCORE. Namely, you forgot to put quotes around the field names...

The code I used was:

var total = 0;

if (this.getField("Group1").valueAsString!="Off") total+=3;

if (this.getField("Group2").valueAsString!="Off") total+=2;

if (this.getField("Group3").valueAsString!="Off") total+=3;

// etc.

event.value = total;

I placed it as the custom calculation script of "PMTotal", just to test it out.

Translate
Community Expert ,
Nov 07, 2018 Nov 07, 2018

You can apply the value as the export value of both fields, but that's not good practice.

Instead, you can do something a bit more complicated, like setting the export values to "Yes|3" and "No|3" and then parse the value of the field to get the number of points for it. Alternatively, you can hard-code the number of points per field in your code.

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

Unfortunately, I have no idea how to do that haha

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

Let's say the questions are called "Q1", "Q2", "Q3", etc.

You can use something like this as the custom calculation script of the field where you want to show the results:

var total = 0;

if (this.getField("Q1").valueAsString!="Off") total+=3;

if (this.getField("Q2").valueAsString!="Off") total+=2;

if (this.getField("Q3").valueAsString!="Off") total+=3;

// etc.

event.value = total;

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

There was an error in the code above. It's fixed now...

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 ,
Nov 14, 2018 Nov 14, 2018

Ok I think I understand where you going with it; however, I have multiple groups with Yes and No options. There is a Yes column and a No column that both need totals respectively. Right now with your script, it's calculating the value assigned for selecting Yes, but if you deselect it to hit no, the total remains the same without taking it back away. So does that mean I have separate the radio dials out of groups so the Yes has its own and the No has its own group? Here's what I'm working with (Green = 1, Blue = 2, Yellow = 3):

example.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 ,
Nov 14, 2018 Nov 14, 2018

No, that should not be the case. Can you share the actual 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
Community Beginner ,
Nov 15, 2018 Nov 15, 2018

Yes, here's a link to the PDF:

https://drive.google.com/file/d/1XvhN_L_m1ZBYHoWRS4Wh63q5-Ln70BiS/view?usp=sharing

I had taken out your code already since I was having issues in case you look for it.

Any help is greatly appreciated!

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 ,
Nov 15, 2018 Nov 15, 2018

Works fine for me, once I adjust the field names in the code.

There is an error in the calculation script of some field, though, and it's producing this message each time a value is changed:

ReferenceError: PM_RAW_TOTAL is not defined

1:Field:Calculate

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 ,
Nov 15, 2018 Nov 15, 2018

Ya, I'm not sure why it's doing that. I have the value of PM_RAW_TOTAL set to be the sum of PMTotal, which is the Yes column of section 1.

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 ,
Nov 15, 2018 Nov 15, 2018

And the code still doesn't work for me. Now it's not calculating anything for me. What's the exact code you used that worked so I can make sure I didn't enter something wrong?

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 ,
Nov 15, 2018 Nov 15, 2018

The problem is with the script for TOTAL_RISK_SCORE. Namely, you forgot to put quotes around the field names...

The code I used was:

var total = 0;

if (this.getField("Group1").valueAsString!="Off") total+=3;

if (this.getField("Group2").valueAsString!="Off") total+=2;

if (this.getField("Group3").valueAsString!="Off") total+=3;

// etc.

event.value = total;

I placed it as the custom calculation script of "PMTotal", just to test it out.

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 ,
Nov 16, 2018 Nov 16, 2018

So I put in your script and fixed the problem with TOTAL_RISK_SCORE. The only issue I'm having now is that when I move my answer from Yes to No (Choice1 to Choice 2), the PM-Total (Yes column) doesn't change to reflect deselecting it.

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 ,
Nov 16, 2018 Nov 16, 2018

Isn't that what you asked for? That the value will be added no matter the selection, as long as the field is not empty?

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 ,
Nov 19, 2018 Nov 19, 2018

No there can only be one answer for Yes or No, so if you deselect Yes to select No, then the Yes column should reflect that change by subtracting, while the No column would increase by selecting another No.

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 ,
Nov 19, 2018 Nov 19, 2018

Then change all of the instances of:

valueAsString!="Off"

To:

valueAsString=="Yes"

Or:

valueAsString=="No"

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 ,
Nov 19, 2018 Nov 19, 2018

I tried by just switching the "Off" to "Yes" and that didn't work, then I tried removing the exclamation point and adding the extra "=" as you did above, but that didn't work. Did I do something wrong?

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 ,
Nov 19, 2018 Nov 19, 2018

Can you share the new 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
Community Beginner ,
Nov 20, 2018 Nov 20, 2018

I've only changed the script for section 1 PM-Total in the Yes Column to test it first.

Java Risk Assessment.pdf - Google Drive

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 ,
Nov 20, 2018 Nov 20, 2018

You didn't set the export values of the radio-button fields to "Yes" and "No", though. They are set to "Choice1" and "Choice2".

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 ,
Nov 20, 2018 Nov 20, 2018

Are you saying to change the "Choice1" and "Choice2" under each group to "Yes" and "No"? Sorry I don't understand what you mean by the export value.

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 ,
Nov 20, 2018 Nov 20, 2018

Yes, that's what I mean.

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 ,
Nov 20, 2018 Nov 20, 2018
LATEST

Ok gotcha. It's working now, so I believe it should be good. I'll go through and change everything and make sure, but otherwise thank you so much! You've been incredibly helpful and patient with me : )

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