Skip to main content
Participant
January 15, 2024
Question

RADIO BUTTONS & JAVA How to make a radio button control other radio buttons is different groups.

  • January 15, 2024
  • 1 reply
  • 821 views

I have 7 Goups of radio buttons (Group 22 - 27 & Group 36). Each group has 2 choices, YES and NO.

 

What Java Script do I need to make a NO selection in Group 26 automatically make Groups 22-27 show NO?

 

But also not affecting the ability to select either YES or NO in Groups 22-27 should a YES be selected in Group 36.

 

I am NOT a programmer or JAVA user just FYI I have no experience.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 15, 2024

To be clear, the name of the Acrobat scripting language is JavaScript (officially known as ECMA script).  Java is a completely different (unrelated) programming language. Just FYI for future reference. 

 

You can read a bit about how radio buttons work, and are scripted, here:

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

 

For the code example I'm assuming you've provided the actual field names.

Place this script on the "MouseUp" Action on  "Group 26"

 

if(event.target.value == "No")

{

    this.getField("Group 22").value = "No"; 

    this.getField("Group 23").value = "No"; 

    ... and repeat for all fields ...

}

 

This script is only run when the user clicks on "Group 26", so the other field values are only set at this time. They can be changed manually by the user after this. 

 

If you want these fields to remain unchanged until the user selects Yes, then code for making the target fields readonly needs to be added.

 

if(event.target.value == "No")

{

    this.getField("Group 22").value = "No"; 

    this.getField("Group 23").value = "No"; 

    ... and repeat for all fields ...

 

    this.getField("Group 22").readonly= true; 

    this.getField("Group 23").readonly= true; 

    ... and repeat for all fields ...

 

}

else

{

  this.getField("Group 22").readonly= false; 

    this.getField("Group 23").readonly= false; 

    ... and repeat for all fields ...

}

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
January 16, 2024

Thanks for that - I will try it - but have a follow-up question - when you tell me to put the MOUSE UP function on group 36 - is it on the YES button or the NO button - or BOTH?

Thom Parker
Community Expert
Community Expert
January 16, 2024

Since these are radio buttons you have some choices.  You can put the same script on both buttons and it will work just fine.  However, a radio button can only be pushed "on", so the MouseUp will always result in the script being run with the value of the button being pushed. So you could also split the script and put the "Yes" part of the script on the Yes button and the "No" part of the script on the No button.

 

 

 

 

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