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

Assign numerical values to radio dials

Community Beginner ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

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

Views

369

Likes

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 , 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.

Likes

Translate

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

Unfortunately, I have no idea how to do that haha

Likes

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

Copy link to clipboard

Copied

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;

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

No, that should not be the case. Can you share the actual file?

Likes

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

Copy link to clipboard

Copied

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!

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

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?

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

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?

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

Then change all of the instances of:

valueAsString!="Off"

To:

valueAsString=="Yes"

Or:

valueAsString=="No"

Likes

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

Copy link to clipboard

Copied

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?

Likes

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

Copy link to clipboard

Copied

Can you share the new file?

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

Yes, that's what I mean.

Likes

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

Copy link to clipboard

Copied

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 : )

Likes

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