Skip to main content
Known Participant
Apr 23, 2025 9:02 PM UTC
Question

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

 

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?

14 replies

Nesa Nurani
Community Expert
Community Expert
Apr 28, 2025 5:58 AM UTC

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;}}}
Translate
JR Boulay
Community Expert
Community Expert
Apr 27, 2025 8:19 PM UTC

[MOVED TO THE ACROBAT DISCUSSIONS]

Translate
Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
Apr 23, 2025 10:47 PM UTC

What are the names of the check-boxes?

Translate
yeungyamAuthor
Known Participant
Apr 23, 2025 11:15 PM UTC

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.

Translate
try67
Community Expert
Community Expert
Apr 24, 2025 9:43 AM UTC

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?

Translate