11 Replies Latest reply on Sep 1, 2017 10:10 AM by AlexJ8

# Help with PDF Radio Button Module

Hey gals & guys,

I am making a self-assessment test with 5 questions. Each question has 3 answers. There is no right or wrong answer. Each of the answers is 0, 1 or 2 points. Is there a way to use JavaScript to calculate the final results and output some text in a field and fill it with color? And is there a way to decide the color based on text? Any help would be greatly appreciated!

• ###### 1. Re: Help with PDF Radio Button Module

Do you just want to show the sum of the selected buttons? If so, it's certainly possible but your choice of values is not so good, as it will not be possible to differentiate between selecting the "0" option and not making any selection at all...

• ###### 2. Re: Help with PDF Radio Button Module

Well, I suppose values of 1, 2 and 3 will work. And yes, showing only the sum will also work. Can we based on that sum color a field and display a label or is that a far-fetched idea?

• ###### 3. Re: Help with PDF Radio Button Module

Yes, that works better. And sure, that's possible... What color/label do you want to display?

• ###### 4. Re: Help with PDF Radio Button Module

Also, what are the names of the radio-button groups?

• ###### 5. Re: Help with PDF Radio Button Module

Well, if the color can be red for a sum of 5 to 9, yellow for 10-11 and 14-15, and green for 12-13 that would be great.

And with label "Good" for red, "Better" for yellow, and "Best" for green.

Also the groups are GR1 to GR5 accordingly.

• ###### 6. Re: Help with PDF Radio Button Module

What if it's below 5?

• ###### 7. Re: Help with PDF Radio Button Module

Well, the questions are 5 so the sum shouldn't be below 5. Maybe for a sum of 1 to 5 display "Please answer all questions" on the label.

• ###### 8. Re: Help with PDF Radio Button Module

Use this code as the custom calculation script of the total field:

```var total = 0;
for (var i=1; i<=5; i++) {
var v = this.getField("GR"+i).value;
if (v!="Off") total+=Number(v);
}

if (total==0) {
event.value = "";
event.target.fillColor = color.transparent;
} else if (total<5) {
event.target.fillColor = color.transparent;
} else if (total>=5 && total<=9) {
event.value = total + " (Good");
event.target.fillColor = color.red;
} else if ((total>=10 && total<=11) || (total>=14 && total<=15)) {
event.value = total + " (Better)");
event.target.fillColor = color.yellow;
} else if (total>=12 && total<=13) {
event.value = total + " (Great)");
event.target.fillColor = color.green;
}
```