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

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

New Here ,
Jan 15, 2024 Jan 15, 2024

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.

TOPICS
Acrobat SDK and JavaScript
726
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 ,
Jan 15, 2024 Jan 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 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
New Here ,
Jan 16, 2024 Jan 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?

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 ,
Jan 16, 2024 Jan 16, 2024
LATEST

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 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