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!
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.
Unfortunately, I have no idea how to do that haha
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;
event.value = total;
There was an error in the code above. It's fixed now...
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):
No, that should not be the case. Can you share the actual file?
Yes, here's a link to the PDF:
I had taken out your code already since I was having issues in case you look for it.
Any help is greatly appreciated!
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
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.
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?
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;
event.value = total;
I placed it as the custom calculation script of "PMTotal", just to test it out.
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.
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?
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.
Then change all of the instances of:
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?
Can you share the new file?
You didn't set the export values of the radio-button fields to "Yes" and "No", though. They are set to "Choice1" and "Choice2".
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.
Yes, that's what I mean.
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 : )