Help with PDF Radio Button Module

Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

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! 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

257

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

Help with PDF Radio Button Module

Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

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! 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

258

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
Sep 01, 2017 0
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

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

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
Reply
Loading...
Sep 01, 2017 1
Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

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?

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
Reply
Loading...
Sep 01, 2017 0
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

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

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
Reply
Loading...
Sep 01, 2017 1
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

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

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
Reply
Loading...
Sep 01, 2017 1
Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

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.

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
Reply
Loading...
Sep 01, 2017 0
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

What if it's below 5?

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
Reply
Loading...
Sep 01, 2017 1
Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

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.

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
Reply
Loading...
Sep 01, 2017 0
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

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;

}

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
Reply
Loading...
Sep 01, 2017 2
Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

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? 

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
Reply
Loading...
Sep 01, 2017 0
Most Valuable Participant ,
Sep 01, 2017

Copy link to clipboard

Copied

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.

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
Reply
Loading...
Sep 01, 2017 1
AlexJ8 LATEST
Community Beginner ,
Sep 01, 2017

Copy link to clipboard

Copied

Thank you so much - that worked perfectly!

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
Reply
Loading...
Sep 01, 2017 0