Skip to main content
AlexJ8
Participating Frequently
September 1, 2017
Answered

Help with PDF Radio Button Module

  • September 1, 2017
  • 1 reply
  • 1506 views

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! 

This topic has been closed for replies.
Correct answer try67

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.


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.value = "Please answer all questions";

    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;

}

1 reply

try67
Community Expert
Community Expert
September 1, 2017

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

AlexJ8
AlexJ8Author
Participating Frequently
September 1, 2017

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?

try67
Community Expert
Community Expert
September 1, 2017

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