Skip to main content
Participant
February 28, 2024
Question

check boxes based on other check boxes

  • February 28, 2024
  • 1 reply
  • 1338 views

Hello!

 

I have YES and NO checkboxes that need to uncheck based on other checkboxes. Basically, 

 

A) Do the following actions occur?   Yes   No

1) action a     Yes     No

2) action b     Yes     No

3) action c     Yes     No

 

If all of the actions are YES, then A) should be YES, but if any are NO then A) should be NO.

Any ideas?

 

Thanks in advance!

 

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
February 28, 2024

To do this, a Calculation script is required, so add a hidden text field.

Next, to write the actual script the field names must be known. Let just say 1), 2), and 3) are "Action1' thru 'Action3', and A) is "QuestionA".

The export value for QuestionA must also be known. I'll assume it is the default value of "Yes".

 

Here's the calculation script

 

var bAllOn = (this.getField("Action1").value != "Off") && (this.getField("Action2").value != "Off")  && (this.getField("Action3").value != "Off") ;

this.getField("QuestionA").value = bAllOn?"Yes":"Off";

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
adrose211Author
Participant
March 4, 2024

Thank you! That worked to turn on the box for question A. I think I need to get more detailed...

 

Each of the questions have these possible answers: Yes, No, and N/A (see attached).

I'd like to automatically have Question A select between the three choices based on the answers to Actions 1, 2, & 3.

 - If they are all Yes (or a combination of Yes and N/A), then QA should be Yes as well. However, if any of the Actions are No, then QA should be No. 

 

Thanks so much for your help!

 

 

 

Thom Parker
Community Expert
Community Expert
March 4, 2024

The solution can be generalized to accomodate any group of checkboxes with this configuration.  To do this the fields need to be named in such a way that all related fields can be found.  It looks like you have a naming scheme that will work for this. Although I would suggest the names are made more specific so they can be uniquely identified using a regular expression. 

For example "Checks.1d2-1", etc.  

 

var rgCheckQ = /Checks\.(\d\w\d)\-\d/

if(event.source  && (rgCheckQ.test(event.source.name))

{

   var cFldBase = "Check." + RegExp.$1;

   

   var bAllOn = (this.getField(cFldBase + "-1").value != "Off") && (this.getField(cFldBase + "-2").value != "Off")  && (this.getField(cFldBase + "-3").value != "Off") ;

   this.getField(cFldBase).value = bAllOn?"Yes":"Off";

}

 

 

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