Skip to main content
NB&T-Ali
Participant
August 10, 2020
Answered

How to make a radio button in one group, select a radio button in a different group

  • August 10, 2020
  • 3 replies
  • 3250 views

Hello,

 

I'm looking for the Javascript to copy and paste in an Adobe PDF fillable form. 

 

I have two groups, Group1 with options A and B, and Group2 with Options C and D. I want to make it so when someone clicks Option B in Group1, then Option C in Group2 is automatically selected. I've done this before with checkboxes, but I can't seem to get it to work with radio buttons. 

 

Thank you for your help! 

This topic has been closed for replies.
Correct answer BarlaeDC

Hi,

 

Using this with Radio Buttons ( that are in different groups the code for this is fairly straight forward.

 

If you add this code to Group 1 box A :

this.getField("Group2").checkThisBox(0, true);

And in Group 1 box B :

this.getField("Group2").checkThisBox(1, true);

 

Because of the way radio buttons work, this also auto unchecks the other one.

 

Gotcha : The radio buttons as added in to the group in the order that you create them in that group, not the order they are on the page.

 

Hope this helps.

 

Malcolm

3 replies

NB&T-Ali
NB&T-AliAuthor
Participant
August 10, 2020

That worked! Thank you so much for your help!

ls_rbls
Community Expert
Community Expert
August 10, 2020
NB&T-Ali
NB&T-AliAuthor
Participant
August 10, 2020

Thank you for your responses! Unfortunately, I'm still unable to figure it out. 
 In another pdf form, I used the following so when checkbox "A" was clicked, 2 other checkboxes were automatically clicked. 

this.getField("checkbox8").value = event.target.value;

this.getField("checkbox8").readonly = (event.target.value == "Yes")

this.getField("checkbox4").value = event.target.value;

this.getField("checkbox4").readonly = (event.target.value == "Yes")

So I was just trying to figure out how to make it radio buttons instead of checkboxes, and 1 option is automatically clicked instead of 2. The script above I copied directly from another forum and just changed my checkbox number. 

BarlaeDC
Community Expert
BarlaeDCCommunity ExpertCorrect answer
Community Expert
August 10, 2020

Hi,

 

Using this with Radio Buttons ( that are in different groups the code for this is fairly straight forward.

 

If you add this code to Group 1 box A :

this.getField("Group2").checkThisBox(0, true);

And in Group 1 box B :

this.getField("Group2").checkThisBox(1, true);

 

Because of the way radio buttons work, this also auto unchecks the other one.

 

Gotcha : The radio buttons as added in to the group in the order that you create them in that group, not the order they are on the page.

 

Hope this helps.

 

Malcolm

ls_rbls
Community Expert
Community Expert
August 10, 2020

That is achieved by  getting the index of the checked radio button (zero-based index method)

 

I just posted a question having a similar issue but I think I found the answer.

 

Look in the Adobe Acrobat SDK, Developing Acrobat Applications Using JavaScript, Page 81  "Setting Acrobat form field properties"   specifically in the "Radio button fields" section Example 6.3Accessing individual radio button widgets