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.

Thom Parker
Community Expert
May 30, 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

 

 


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 PDFScriptingUse the Acrobat JavaScript Reference early and often