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

Enable/Disable Radio Button Group with Checkbox state?

Community Beginner ,
Nov 12, 2019 Nov 12, 2019

I have two groups of radio buttons. The first choice in both groups must always be selected together, checking one will check the other. I changed these first choice fields to checkboxes with the same name so they check together, but I need to have this checkbox disable (read only) the remaining radio buttons when checked, and enable them when unchecked. I applied this checkbox mouseup javascript to make the radio buttons read only, but the radio buttons stay read only if the checkbox is unchecked.

this.getField("X8").readonly=true;
this.getField("X9").readonly=true;

How can I make the radio buttons toggle back to enabled if the checkbox is unchecked?

TOPICS
PDF forms
6.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
Community Expert ,
Nov 12, 2019 Nov 12, 2019

You need to use the state of the checkbox to set the readonly state.

For example:

 

this.getField("X8").readonly= (event.target.value!="Off");

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 13, 2019 Nov 13, 2019

Thom, I really appreciate your help. You are all over this Community helping others. You are very generous with your time and knowledge!

I took a different path and have a new problem:
I changed my two groups of selections to all checkboxes with different export values.
(Group 1; three checkboxes with values 0, 1, 2 and Group 2; three checkboxes with values 0, 1, 2)

I need the first two boxes in each group (val 0) to check/uncheck together, and disable all other checkboxes options in both groups. If any different checkbox from either group is checked (val 1 or 2), it must uncheck the two val 0 boxes.

Here's the problem: The two val 0 boxes check/uncheck together as desired, however if I check a value 1 or 2 box, it does not uncheck the value 0 box in the other group. It does uncheck the val 0 box within the group it resides. How do I make any other checkbox selections in either group uncheck BOTH 0 value boxes? All other selections are independent of each other.

Here's my setup:
Mouseup Javascript to checkbox Group 1 val 0:
this.getField("Group 1").value = event.target.value; this.getField("Group 1").readonly = (event.target.value == "Yes"); this.getField("Group 2").value = event.target.value; this.getField("Group 2").readonly = (event.target.value == "Yes");

 

Mouseup Javascript to checkbox Group 2 val 0:

this.getField("Group 2").value = event.target.value; this.getField("Group 2").readonly = (event.target.value == "Yes"); this.getField("Group 1").value = event.target.value; this.getField("Group 1").readonly = (event.target.value == "Yes");

FYI, I am a totally ignorant of Javascript. If there's a better way to do this I'm all over it.
Thank you VERY much.

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 ,
Nov 13, 2019 Nov 13, 2019

You're script is on the MouseUp of only the first checkbox. Therefore, it only executes when the first checkbox is clicked. 

The solution is to do one of two things.

1. Put appropiate scripts on the MouseUp of all checkboxes. This is the easiest solution. 

2. Use a script that is triggered when the value of the checkbox group is changed, such as a validation for format script. These value related scripts can only be set using a script. An alternative is to use a calculation script on a hidden text field, but I wouldn't recomend it. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 13, 2019 Nov 13, 2019

Thom,
I like your suggestion #1 since it's the easiest. Unfortunately, I have no idea what an "aapropriate" script would be. If I were just using checkbox names, I could probably figure it out, but since I'm now using a checkbox group with values, I just don't even know where to begin.

I found this similar situation from a Mar 12, 2018 post but can't wrap my head around how it could modified for my situation:

var bChecked = (event.target.value == "Yes")

this.getField("checkbox3").readonly = bChecked;

this.getField("checkbox2").readonly = bChecked;

if(bChecked)

{

     this.getField("checkbox3").value = "Off";

     this.getField("checkbox2").value = "Off";

}

Could this be modified to uncheck my val 0 selcetions? If I had an example to get started, I usually figure it out. Thanks!

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 ,
Nov 13, 2019 Nov 13, 2019

So I think you need to read some more about using radio buttons and checkboxes.

Here's a link that will help:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

So, first, the "group" name is in fact the field name. Next, you stated that you changed the "export" values to 0,1, and 2. This means that the value of the field (i.e. group) will never be "Yes", it can only be "Off", 0, 1, or 2.  "Yes" is the default export of a checkbox. If you change the export, then you don't get a "Yes". 

Now, you also stated the fields were named "Group1" and "Group2" so what's this "checkbox2" and "checkbox3"? 

 

I would strongly suggest using "console.println()" statements in your code so you can ensure you know exactly the values being returned in the mouseup scripts.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 14, 2019 Nov 14, 2019

Thom,
Sorry if I'm confusing. I'm a graphic designer with a rudimentary understanding of Javascript and terminology. I actually did read and study that link to psfscripting.com—in fact, that's where I got the idea to use checkboxes with values. I also have been viewing your multiple tutorials online. Pardon my ignorance, but I recognize my previous errors, and only posted that other code as an example. Nonetheless, I'd sure appreciate getting this solved.

 

Again, here's my situation:

I have two groups of checkboxes with different export values.
(Group 1: three checkboxes with values 0, 1, 2; and Group 2: three checkboxes with values 0, 1, 2)

I need the first two boxes in each group (val 0) to check/uncheck together, and uncheck all other checkboxes options in both groups. If any other checkbox (val 1 or 2) from either group is checked, it must uncheck the two val 0 boxes.

 

Here's the problem I'm having:
The two val 0 boxes check/uncheck together as desired, however if I check a value 1 or 2 box, it does not uncheck the value 0 box in the other group. It does uncheck the val 0 box within the group it resides. How do I make any other checkbox selections in either group uncheck BOTH 0 value boxes?

 

Here's code I am using:

Mouseup Javascript to checkbox Group 1 val 0:

this.getField("Group 1").value = event.target.value;

this.getField("Group 2").value = event.target.value;

 

Mouseup Javascript to checkbox Group 2 val 0:

this.getField("Group 1").value = event.target.value;

this.getField("Group 2").value = event.target.value;

 

I need more help with your suggestion to "Put appropiate scripts on the MouseUp of all checkboxes". For the remaining checkboxes, how would I script "if values 1 or 2 are checked, then value 0 is unchecked". Unchecked would be "Off", right?

 

I'm still learning…Thanks for any additional help.

PS: I wouldn't know how to utilize "console.println()" statements, but I'd sure like to know

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 ,
Nov 14, 2019 Nov 14, 2019

Thank you for the clear explanation. 

 

Here's the mouseup code you need:

 

Group 1, val 0:

 this.getField("Group 2").value = event.target.value;

 

Group 1, val 1 and val 2:

 this.getField("Group 2").value = "Off";

 

Group 2, val 0:

 this.getField("Group 1").value = event.target.value;

 

Group 2, val 1 and val 2:

 this.getField("Group 1").value = "Off";

 

Short and simple 🙂

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 14, 2019 Nov 14, 2019

Thank you, but not quite…

Checking the boxes with values 1 or 2 unchecks the value 0 boxes correctly,🙂

However,

Checking a box with value 1 or 2 also unchecks all boxes in the other Group, making them uncheckable.

The check boxes with values 1 or 2 in both Groups must be able to be checked independently…I should be able to check a box value 1 or 2 from Group 1 AND Group 2.

 

In other words,

If any other checkbox (val 1 or 2) from either group is checked, it must uncheck the two val 0 boxes ONLY.

 

I hope this is clear. Thank you!Thank you!

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 ,
Nov 14, 2019 Nov 14, 2019

Ohhh, getting more complicated. This the importance of clarity.  You see, there are only two fields, group1 and group2. All of the check boxes in a group are the same field, there is no unchecking just the box 0 value. You have to state this as a condition. If the box 1 or 2 values are selected, then they uncheck the other group only if the 0 value in that group is selected. So just change the code to add that condition. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 14, 2019 Nov 14, 2019

Its so nice to know that you think I'd know how to do that…

Can you give a me a clue how I would code the condition "If the box 1 or 2 values are selected, then they uncheck the other group only if the 0 value in that group is selected"

 

I'm in over my head ðŸ¤”

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 ,
Nov 14, 2019 Nov 14, 2019

You really aught to either consider heiring someone or spending the time to learn about how to do what you need.

Here's an article on writing conditionals

https://acrobatusers.com/tutorials/conditional-execution

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 14, 2019 Nov 14, 2019

I get it, Thom.

Thanks for your help.

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
New Here ,
May 29, 2021 May 29, 2021

Hi Tom, what if the first group of checkbox with the same field name and differe exportvalues of Soap, Apples, Shoes were exclusionary. So that if you selected Soap, you couldn't also select Apples.  If you select soap, and decide on apples, that event would cause the Soap to be unchecked and the Apples checked. They must be mutually exclusive.  Then I need a calculation related to the product checked  that will multiply the cost of the product selected by the quanity (also selected by the end user).So if we're looking at a table, the column headings would be: Poduct  quntity (variable) x  Cost = Total 

                 Soap            3                       $2.00 = $6.00

                 Apples          ""                     ""            ""

                 Snails           ""                     ""             ""....etc

 

 

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 ,
May 30, 2021 May 30, 2021
LATEST

So, you want the regular (cost * quantity) calculation to only proceed if the associated checkbox is clicked?

 

This is a different topic than the thread, but here's a sample calculation for the Apples line

 

if(this.getField("Group1").value == "Apples")

{

     event.value = .. Calculation for Apple line...

}

else

    event.value = "";

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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