Skip to main content
Participant
September 21, 2023
Question

If two boxes are checked, third box will auto check

  • September 21, 2023
  • 1 reply
  • 781 views

Hi everyone! 

I need help. Can someone provide me the script for this:

 

- if c1 and c2 is checked, c3 will be checked 

- if c1 is checked, but c2 is unchecked, c3 will not be checked 

 

Thank you! 

 

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
September 21, 2023

The problem here is that a checkbox does not have a custom calculation script that would allow you to determine if the checkbox should be checked or not, so we need to find a different way to accomplish this. I often use a hidden text field do perform this task for me. Another solution would be to write a document level function to update the checkbox, which gets called on any click action on the other two checkboxes. 

 

I will use the first approach here. Create a text field and mark it as read-only and hidden. Create a custom calculation script for the text field and then use this script:

 

// only check "Check Box3" if both "CheckBox 1" and "CheckBox 2" are checked.
console.println(this.getField("Check Box1").value);
console.println(this.getField("Check Box2").value);
console.println(this.getField("Check Box3").value);
if (this.getField("Check Box1").value != "Off" && this.getField("Check Box2").value != "Off") {
    this.getField("Check Box3").value = "Yes";
}
else {
    this.getField("Check Box3").value = "Off";
}
Nesa Nurani
Community Expert
Community Expert
September 21, 2023

Might be better to use checkThisBox() instead in case export value is not "Yes".

Participant
September 21, 2023

I'll keep that in mind! Thank you for mentioning that. For now, all is Yes but will be changing it later.