Skip to main content
Participant
April 1, 2024
Question

How to automatically uncheck boxes connected to radio button?

  • April 1, 2024
  • 1 reply
  • 983 views

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!

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
April 1, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
April 1, 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?

Thom Parker
Community Expert
Community Expert
April 1, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often