# Set of 6 mutually exclusive checkboxes, but several with the same values

Community Beginner ,
Feb 27, 2021 Feb 27, 2021

Copied

I have a set of 6 items, each with a price. The form user needs to make a mutually exclusive choice among these checkboxes, with the selection determining the value of a total field I would assign the items/prices all the same name, but out of the 6 items, 2 pairs share a price:
Item 1 = \$50
Item 2 = \$75

Item 3 = \$100

Item 4 = \$100

Item 5 = \$125

Item 6 = \$125

Of course, this means that if the user checks item 3, item 4 also becomes active; the same holds true for items 5 and 6.

I tried assigning each item an arbitrary value (1 through 6), having a calculation test for the value, and on the basis of the value, assigning the price to the total, but I can't get the calculation to work.

Here's the calculation I have. Feel free to sneer at my beginnerism:

``````var TOTAL = 0;
if ((this.getField("01").valueAsString)=="1") TOTAL=50;
if ((this.getField("02").valueAsString)=="2") TOTAL=75;
if ((this.getField("03").valueAsString)=="3") TOTAL=100;
if ((this.getField("04").valueAsString)=="4") TOTAL=100;
if ((this.getField("05").valueAsString)=="5") TOTAL=125;
if ((this.getField("06").valueAsString)=="6") TOTAL=125;
event.value = TOTAL;``````

Is there a way around this? I considered building these checkboxes as a set of square radio buttons, which would make them mutually exclusive by definition, but the line thickness of square radio buttons is greater than the line thickness of the large number of checkboxes already in this document. This is a situation in which design actually is an essential part of obtaining a satisfactory result.

TOPICS
PDF forms

Views

115

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Most Valuable Participant , Feb 28, 2021 Feb 28, 2021
Another option to the one suggested above by @JR Boulay is to separate the export value from the price. As the export value use "1", "2", "3", etc., and then in your calculation code convert it to a price, like this (let's say the name of the group is "Radio1"):   var v = this.getField("Radio1").valueAsString; if (v=="1") event.value = 50; else if (v=="2") event.value = 75; else if (v=="3" || v=="4") event.value = 100; else if (v=="5" || v=="6") event.value = 125; else event.value = "";

Likes

13 Replies 13
Feb 27, 2021 Feb 27, 2021

Copied

The solution is very simple.

For a radio-buttons/checkboxes set: 125 is not the same value than 125.0 which is not the same value than 125.00, etc.

They are not the same "value" but they are the same "number", so you can use these items as "Export value" and use the "Sum" calculation without needing a script:

Item 1 = \$50
Item 2 = \$75

Item 3 = \$100

Item 4 = \$100.0

Item 5 = \$125

Item 6 = \$125.0

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 28, 2021 Feb 28, 2021

Copied

That's an interesting suggestion. I tried using 200/2 for one of the duplicates and 250/2 for the other, but the fields would not calculate.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 28, 2021 Feb 28, 2021

Copied

Just to add up about radio buttons,  go to appearance and change line style to "solid" it will be same thickness as checkbox.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 28, 2021 Feb 28, 2021

Copied

I tried that, but even with the radio-button line weight set to "Thin," the line weight is much thicker on the radio buttons than it is on checkboxes. Acrobat's field-appearance tools are crude compared to other Adobe applications.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Feb 28, 2021 Feb 28, 2021

Copied

Read posts more carefully, line weight and line style are not the same option. If you set line style to solid as suggested it should be same as checkbox.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 28, 2021 Feb 28, 2021

Copied

Thank you for your instructive reply. You are indeed correct. However, was it entirely necessary to be so brusque?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Feb 28, 2021 Feb 28, 2021

Copied

Don't mind it, thats how I sound but it was not my intention.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 28, 2021 Feb 28, 2021

Copied

Check the Javascript console for errors.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 28, 2021 Feb 28, 2021

Copied

I did, but unfortunately, my current level of understanding is too rudimentary to interpret the messages correctly. If this were AppleScript, I'd have a clue. 😉

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Feb 28, 2021 Feb 28, 2021

Copied

Another option to the one suggested above by @JR Boulay is to separate the export value from the price.

As the export value use "1", "2", "3", etc., and then in your calculation code convert it to a price, like this (let's say the name of the group is "Radio1"):

``````var v = this.getField("Radio1").valueAsString;
if (v=="1") event.value = 50;
else if (v=="2") event.value = 75;
else if (v=="3" || v=="4") event.value = 100;
else if (v=="5" || v=="6") event.value = 125;
else event.value = "";``````

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 28, 2021 Feb 28, 2021

Copied

This was the approach I took, and it worked perfectly. Not to say that other suggestions were incorrect.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Feb 28, 2021 Feb 28, 2021

Copied

My thanks to everyone for the assistance. I wish there were a cohesive learning guide that addressed these kinds of situations, but apparently, Acrobat's Javascript implementation is enough different from "regular Javascript" that standard tutorials aren't always applicable.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 01, 2021 Mar 01, 2021

Copied

JavaScript is the same everywhere.

The difference is the "objects" and their properties.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources