Skip to main content
Henry.Ong
Inspiring
May 15, 2025
Answered

How to select at least two from a list of checkboxes?

  • May 15, 2025
  • 3 replies
  • 620 views

Hi again Nesa,

 

You have provided a solution for selecting only two from a list of checkboxes. And for that, I thank you.

 

Here is the script you have provided ...

var boxes = [];
for (var i=1; i <=7; i++) {
 boxes.push(this.getField("CB" + i));}

var offBoxes = boxes.filter(function(f) {
 return f.valueAsString === "Off";});

var readonly = (offBoxes.length === 5);

offBoxes.forEach(function(f) {
 f.readonly = readonly;});

 

But the requirement has changed. Instead of Select only two from the list, it is now Select at least two.

 

How would the scipt be if this is now the requirement. Thanks.

Correct answer radzmar

Hi,

the solution is quite similar. 

var boxes = [];
for (var i=1; i <=7; i++) {
 boxes.push(this.getField("Check Box" + i));
}

var onBoxes = boxes.filter(function(f) {
 return f.valueAsString !== "Off";}
);

if (onBoxes.length < 2) {
    app.alert("Select at least 2 options!");
}

3 replies

radzmar
Community Expert
radzmarCommunity ExpertCorrect answer
Community Expert
May 15, 2025

Hi,

the solution is quite similar. 

var boxes = [];
for (var i=1; i <=7; i++) {
 boxes.push(this.getField("Check Box" + i));
}

var onBoxes = boxes.filter(function(f) {
 return f.valueAsString !== "Off";}
);

if (onBoxes.length < 2) {
    app.alert("Select at least 2 options!");
}
Henry.Ong
Henry.OngAuthor
Inspiring
May 19, 2025

Hi Radzmar,

 

While you have provided a correct solution, I am encountering a message "Select at least 2 options from the list!" when I try to first complete other fields in the form.

 

The script you have provided is define in a fieldname call "DUMMY" which I set to hidden.

 

I am attaching here the form I have created to you can see what I mean. Thanks.

Bernd Alheit
Community Expert
Community Expert
May 19, 2025

This happens when you use the script at calculation.