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

Help with PDF Radio Button Module

Community Beginner ,
Sep 01, 2017 Sep 01, 2017

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! 

TOPICS
Acrobat SDK and JavaScript , Windows
1.3K
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 , Sep 01, 2017 Sep 01, 2017

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

...
Translate
Community Expert ,
Sep 01, 2017 Sep 01, 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...

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 ,
Sep 01, 2017 Sep 01, 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?

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 ,
Sep 01, 2017 Sep 01, 2017

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

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 ,
Sep 01, 2017 Sep 01, 2017

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

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 ,
Sep 01, 2017 Sep 01, 2017

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.

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 ,
Sep 01, 2017 Sep 01, 2017

What if it's below 5?

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 ,
Sep 01, 2017 Sep 01, 2017

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.

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 ,
Sep 01, 2017 Sep 01, 2017

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;

}

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 ,
Sep 01, 2017 Sep 01, 2017

It accepts the code but when the radio buttons are selected, nothing happens. Should I assign values to the radio buttons separately and how should the output field be named? 

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 ,
Sep 01, 2017 Sep 01, 2017

Yes, you have to assign "1", "2" and "3" as the "Radio button choice" values for your fields.

The name of the output field doesn't matter.

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 ,
Sep 01, 2017 Sep 01, 2017
LATEST

Thank you so much - that worked perfectly!

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