Skip to main content
Participating Frequently
July 30, 2024
Answered

Show/hide checkboxes

  • July 30, 2024
  • 1 reply
  • 1092 views

I have a form with a dropdown ("Decision") with four options that include:

Select one

refuses the parental request for an evaluation.

accepts the parental request for an evaluation.

proposes the evaluation.

 

I then have 16 checkboxes that should ONLY be visible if one of the two final ones are selected (accepts and proposes). If the dropdown is "Select one" or refuses, they should remain hidden.

 

I've tried a variety of things, but can't make it work (yes, I used ChatGPT to help me, so I'm sure there are errors, but I can't figure out what they are!). 

 

Most recently, I've tried a Validation Script of

var decisionField = this.getField("Decision");
var checkboxFields = ["Checkbox1", "Checkbox2", "Checkbox3", "Checkbox4", "Checkbox5", "Checkbox6", "Checkbox7", "Checkbox8", "Checkbox9", "Checkbox10", "Checkbox11", "Checkbox12", "Checkbox13", "Checkbox14", "Checkbox15", "Checkbox16"];
var decisionValue = decisionField.value;

for (var i = 0; i < checkboxFields.length; i++) {
var checkbox = this.getField(checkboxFields[i]);
if (decisionValue === "accepts the parental request for an evaluation" || decisionValue === "proposes the evaluation") {
checkbox.display = display.visible;
} else {
checkbox.display = display.hidden;
}
}

 

It isn't working right. Sometimes it shows the checkboxes and sometimes it doesn't, but it's not clearly based on the response to "Decision." I think perhaps it isn't updating like it should, but don't really know what is going on. Does anyone have suggestions? Thanks!

This topic has been closed for replies.
Correct answer PDF Automation Station

Make sure Commit select value immediately is selected in the options tab of the Decision dropdown and enter this custom validation script in the dropdown:

 

if(event.value=="Select one" || event.value=="refuses the parental request for an evaluation.")
{this.getField("Checkbox").display=display.hidden}
else
{this.getField("Checkbox").display=display.visible}

 

 

1 reply

PDF Automation Station
Community Expert
Community Expert
July 30, 2024

In the options tab of the dropdown, check "Commit selected value immediately".  Remove the first line of your script and change 

var decisionValue = decisionField.value; to var decisionValue=event.value;

Here's a tip:  If you create one check box ("Check Box") and use right-click > create multiple copies to create the rest, you'll have Check Box.0 through Check Box.15.  You can then change the visibility of all of them without listing them in an array and instead using this.getField("Check Box").display=display.hidden;

Participating Frequently
July 31, 2024

Thanks! I had initially made multiple copies but ... long story. I still couldn't get it to work, so deleted my checkboxes to start again. I did the make multiple copies and now have Checkbox.0.0 through Checkbox.7.1 

 

I still can't get the code to work right. I've double checked everything I can think of, but at this point the checkboxes are just visible all the time.

 

But I'm also having the issue that my changes to the validation script don't seem to be "sticking." I'll copy a new attempt at the code in and click "Ok." When I go back to check it, it just says updateCheckboxesVisibility(); and nothing else. 

 

Any thoughts? I feel like it's something minor, but can't figure it out. Thanks!

 

 

PDF Automation Station
Community Expert
Community Expert
July 31, 2024

Make sure Commit select value immediately is selected in the options tab of the Decision dropdown and enter this custom validation script in the dropdown:

 

if(event.value=="Select one" || event.value=="refuses the parental request for an evaluation.")
{this.getField("Checkbox").display=display.hidden}
else
{this.getField("Checkbox").display=display.visible}