Skip to main content
Participant
February 27, 2023
Question

Checkbox conditions based on another checkbox

  • February 27, 2023
  • 3 replies
  • 6195 views

Im fairly new to this and need assistance.  I have a set of checkbox that need to meet certain conditions.  Here are the conditions.  I have two columns of checkboxes.  Column one has checkbox 1, 2 and 3 and column two has 4, 5, and 6.  If checkbox 1 is checked then checkbox 3 is checked automatically.  If checkbox 2 is checked then checkbox 3 is checked automatically.  If checkbox 4 is checked then checkbox 6 is checked automatically and if checkbox 5 is checked then checkbox 6 is automatically checked.  Here is the other part that i need assistance with.  If checkbox 1 is checked then checkbox 4 is disabled and checkbox 3 is checked automatically.  If checkbox 2 is also checked then checkbox 5 is disabled and checkbox 3 is still checked, but if checkbox 5 is checked then checkbox 2 is disabled and checkbox 4 is unchecked. 

This topic has been closed for replies.

3 replies

Participant
May 17, 2024

Aloha from Hawaii.  I'm learning about acrobat and have several applications for which acrobat is perfect for.  I have a somewhat similar question.  However, my requirement is that once All checkboxes are checked a final checkbox automatically becomes checked indicating the completion of the assigned task.  Is this something that can be done in Javascript?  If so, I really don't know javascript how would this be executed?  The current project I'm working on has seven (7) training requirements and when each is completed they check a box.  As a show of completion there is a "Completed" checkbox which I would like to automatically be select once All other requirements are met.

Nesa Nurani
Community Expert
Community Expert
May 17, 2024

Can you share the file or tell us the name of the checkboxes?

Participant
February 29, 2024

box1
if(this.getField("Box1").valueAsString!="On"){this.getField("Box2").value="Off";}

 

box2
if(this.getField("Box2").valueAsString!="On"){this.getField("Box1").value="Off";}

Nesa Nurani
Community Expert
Community Expert
February 29, 2024

The state of the checkbox when checked is not 'On' unless you set its export value to be 'On'.

Are you are trying to create mutually exclusive checkboxes? There is an easier solution to do so:

Give both checkboxes same name but different export value.

Participant
March 12, 2024

Are those mutually exclusive checkboxes or single?

Is 'YES' export value of those checkboxes?

Can you share the file?


Correct they are manually enter checkboxes. Yes, "YES" is the expeort value of those boxes (C1-3) and "NO" to (C6-8). I need to Check Box 4 answer "yes" when CB (1-3) are "YES". Any other answer check box should be check "NO", I added a screen shot. 

Nesa Nurani
Community Expert
Community Expert
February 27, 2023

See if this works for you, use it in a text field as custom calculation script:

var c1 = this.getField("checkbox 1");
var c2 = this.getField("checkbox 2");
var c3 = this.getField("checkbox 3");
var c4 = this.getField("checkbox 4");
var c5 = this.getField("checkbox 5");
var c6 = this.getField("checkbox 6");


if(c1.isBoxChecked(0,true)){
c3.checkThisBox(0,true);
c4.readonly = true;}
else
c4.readonly = false;

if(c2.isBoxChecked(0,true)){
c3.checkThisBox(0,true);
c5.readonly = true;}
else
c5.readonly = false;

if(c4.isBoxChecked(0,true))c6.checkThisBox(0,true);

if(c5.isBoxChecked(0,true)){
c6.checkThisBox(0,true);
c2.readonly = true;
c4.checkThisBox(0,false);}
else
c2.readonly = false;
Participant
February 28, 2023

Thank you for your response.  what you provided did work but not the way I need it to work.  When c1 is checked, c3 is checked which is good.  but when i uncheck c1, c3 is still checked.  i need it to uncheck automatically.  Here is what would like for this to work.

 

Yes Column

If c1 is checked then c3 is checked automatically and c4 is disabled

If c2 is checked then c3 is checked automatically and c5 is disabled

c3 should not be a checkable, possibly be a readonly box that is checked on when c1 or c2 is checked

same thing should happen for No column

Here is the twist.  If c4 is checked and of course c6 is checked. if c2 is checked then c6 needs to be unchecked automatically.  and of course since c2 is checked c3 will be checked automatically.  Basically if there are any check marks in the Yes column then the No column c6 is automatically unchecked.  i hope this makes sense.

Nesa Nurani
Community Expert
Community Expert
February 28, 2023

Try this:

var c1 = this.getField("checkbox 1");
var c2 = this.getField("checkbox 2");
var c3 = this.getField("checkbox 3");
var c4 = this.getField("checkbox 4");
var c5 = this.getField("checkbox 5");
var c6 = this.getField("checkbox 6");


c3.checkThisBox(0,(c1.valueAsString != "Off" || c2.valueAsString != "Off"));
if(c1.valueAsString != "Off"){
c4.value = "Off";
c4.readonly = true;}
else
c4.readonly = false;
if(c2.valueAsString != "Off"){
c5.value = "Off";
c5.readonly = true;}
else
c5.readonly = false;
c6.checkThisBox(0,c3.valueAsString == "Off" && (c4.valueAsString != "Off" || c5.valueAsString != "Off"));