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

How to automatically uncheck boxes connected to radio button?

Community Beginner ,
Apr 01, 2024 Apr 01, 2024

Hi,

I have a set of radio buttons connected to checkboxes. This connects a quiz to the answer key to make it easier to mark. While on some parts of the quiz I can use radio buttons for both quiz and answers, some answers need to toggle more than one selection in the answer key (so if the person selects answer A, it marks as correct for two answers on the answer key so it simulates branches), which you can't do with radio buttons.  I've connected the quiz to the answer key, but when I change the radio button selection or undo the answer to clear it, the checkboxes stay checked. This would (obvously) skew the score if all checkboxes are tallied because someone changed an answer. How do I connect it so that when the radio selection clears or changes, so do the checkboxes connected to it?

This is the code I'm using (In the mouse-up action on the radio buttons)

this.getField("CheckBox1").value = "Yes";

Thanks for any help you can offer!

TOPICS
How to , PDF , PDF forms
1.0K
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 ,
Apr 01, 2024 Apr 01, 2024

The MouseUp is an interactive event, meaning that it is triggered by a user action.  The type of behavior you are concerned with is related to the field value, i.e., when the value of one thing changes, it affects the value of another thing. So, what you really need is an event that is triggered on a value change, i.e., a value event (ex: calculate and validate). The ideal solution would be to use a validate event on the radio button. Checkboxes and radio button really do have validate and calculate events, they just aren't provided in the UI.    So the next best thing is to use a calculate event on a hidden text field. 

 

Use code like this in the calculation script instead of the MouseUp. This will handle both clicks on and off, as well as form resets. 

 

this.getField("CheckBox1").value = (this.getField("Radio1").value == "Something")?"Yes":"Off";

 

 

 

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
Community Beginner ,
Apr 01, 2024 Apr 01, 2024

Okay, perfect. That's what I'm doing for my radio buttons in another section (where one answer corresponds to one mark on the answer key). Would I need to do this for every check box/radio choice? Or is there a way to do this by group thing the way you can with radio buttons?

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 ,
Apr 01, 2024 Apr 01, 2024

All of the code can go into the same calculation script, there is no need for separate hidden text fields. 

The other alternative is to use console scripts to setup a Validate script for each radio button group. 

 

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
Community Beginner ,
Apr 01, 2024 Apr 01, 2024

I tried to use one text field for all of them, but it did not work. Is there a way you have to separate the different fields, like hit enter between them? I started each checkbox on a new line but it won't work that way apparently, ie

this.getField("CheckBox1a").value = (this.getField("Radio1").value == "a")?"Yes":"Off"

this.getField("CheckBox1b").value = (this.getField("Radio1").value == "b")?"Yes":"Off"

this.getField("CheckBox1c").value = (this.getField("Radio1").value == "c")?"Yes":"Off"

this.getField("CheckBox2a").value = (this.getField("Radio2").value == "a")?"Yes":"Off"

this.getField("CheckBox2b").value = (this.getField("Radio2").value == "b")?"Yes":"Off"

this.getField("CheckBox2c").value = (this.getField("Radio2").value == "c")?"Yes":"Off"

 

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 ,
Apr 01, 2024 Apr 01, 2024

Each Line must end with a semi-colon ";"

 

did you check the console window for errors?

 

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
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

So I did it within one text box, as I showed above (I do have the semicolons in the code itself but not in the copy-paste i put here, sorry!) and when i run it in the console window, it doesn't flag anything. when i keep the console window up and running and tick one of the radio buttons, I get a line of this error over and over again,

 

TypeError: this.getField(...) is null
1:Field:Calculate

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 ,
Apr 02, 2024 Apr 02, 2024
LATEST

That error means that the field name used in the code is incorrect. Fields names are case sensitive. Make sure the name of the field in the code matches the field name on the form, verbatim.

 

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