Skip to main content
Known Participant
November 12, 2019
Question

Enable/Disable Radio Button Group with Checkbox state?

  • November 12, 2019
  • 1 reply
  • 6745 views

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?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
November 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
November 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.

Known Participant
November 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 🙂

 


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!