Skip to main content
diegoc31283334
Known Participant
July 23, 2018
Answered

How to create a checkbox that enables or disables based on one or many other selected checkboxes?

  • July 23, 2018
  • 1 reply
  • 1007 views

I have one checkbox called AIR, I want it to be read only. This checkbox should be enabled or disabled based on other checkboxes value(s). So for example: "air freight" or "airway" or" aircraft" are checked then check "AIR". If I uncheck one of this items "air freight" or "airway" or" aircraft", I want AIR to remain checked. Only if all are unchecked AIR should be unchecked, too.

This topic has been closed for replies.
Correct answer Thom Parker

Since there are multiple sources for setting the "Air" checkbox, then this action is best handled with a calculation script. Unfortunately there is not a publicly accessible calculation script on a checkbox. So you'll need to create a hidden text field. The only purpose of this text field is to provide the calculation event needed for setting the checkbox.

Here is the calculation script

var bIsSet = this.getField("air freight").isBoxChecked(0) ||  this.getField("airway").isBoxChecked(0) ||  this.getField("aircraft").isBoxChecked(0);

this.getField("AIR").checkThisBox(0,bIsSet);

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
July 24, 2018

Since there are multiple sources for setting the "Air" checkbox, then this action is best handled with a calculation script. Unfortunately there is not a publicly accessible calculation script on a checkbox. So you'll need to create a hidden text field. The only purpose of this text field is to provide the calculation event needed for setting the checkbox.

Here is the calculation script

var bIsSet = this.getField("air freight").isBoxChecked(0) ||  this.getField("airway").isBoxChecked(0) ||  this.getField("aircraft").isBoxChecked(0);

this.getField("AIR").checkThisBox(0,bIsSet);

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