Skip to main content
Known Participant
April 23, 2025
Question

Make checkboxes hidden/visible for 22 fields with same parent name

  • April 23, 2025
  • 3 replies
  • 1080 views

 

I have a form that have fields: "Normal", "NotPresent", "P", "S".

The are all named as Normal1, Normal2, Normal3, etc until Normal22 and same for the other fields.

Right now I have written the ame code in each of the checkboxes, but when I need to make a change I would have to go to each 22 fields to make the change.

 

This the code for Normal1:

if(event.target.value ==(0)) {

getField("Normal1").required = false;
getField("NotPresent1").required = false;
getField("P1").required = false;
getField("S1").required = false;

this.getField("NotPresent1").display = display.hidden;
this.getField("P1").display = display.hidden;
this.getField("S1").display = display.hidden;

} else {

getField("Normal1").required = true;
getField("NotPresent1").required = true;
getField("P1").required = true;
getField("S1").required = true;

this.getField("NotPresent1").display = display.visible;
this.getField("P1").display = display.visible;
this.getField("S1").display = display.visible;
}

 

How do I make it go through Normal22 with the same code?

3 replies

Nesa Nurani
Community Expert
Community Expert
April 28, 2025

If I understand correctly, the intended behavior is as follows:

  • When one checkbox in a row is checked, that checkbox remains visible and not required, while the other checkboxes in the same row are set to hidden and not required.

  • If none of the checkboxes in a row are checked, all checkboxes in that row become visible and required.

This logic should apply consistently across all rows?

You can remove other script and place this script as custom calculation script in one text field (it can be hidden):

for (var i=1; i<=22; i++) {
 var fields = [
  this.getField("Normal" + i),
  this.getField("NotPresent" + i),
  this.getField("P" + i),
  this.getField("S" + i)
 ];

 var active = -1;
 for (var j=0; j<fields.length; j++) {
  if (fields[j].valueAsString !== "Off") {
   active = j;
   break;}}

 for (var j=0; j<fields.length; j++) {
  if (active !== -1) {
   fields[j].required = false;
   fields[j].display = (j === active) ? display.visible : display.hidden;} 
  else {
   fields[j].required = true;
   fields[j].display = display.visible;}}}
JR Boulay
Community Expert
Community Expert
April 27, 2025

[MOVED TO THE ACROBAT DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
April 23, 2025

What are the names of the check-boxes?

yeungyamAuthor
Known Participant
April 23, 2025

They are all checkboxes. When Normal is checked off, it returns a value of "0".

All I want is to have the other checkboxes hidden when the test is Normal.

try67
Community Expert
Community Expert
April 24, 2025

I understood that, but if you want the code to all be located in a single location, so you could easily edit it, it needs to contain the actual field names of those fields. So what are they?