Skip to main content
Participating Frequently
March 27, 2018
Answered

go through several checkboxes if all checked than check one checkbox

  • March 27, 2018
  • 1 reply
  • 909 views

Hello,

I do not have much experience in Java, please help me.

I want to write such a command -> only if all checkboxes are checked then this checkbox "cb0" should be automaticaly checked.

What is false in my code?

var 1=getField("cb1").value;
var 2=getField("cb2").value;
var 3=getField("cb3").value;

for (i = 1; i < 3; i++){
   if(event.target.value=="Yes"){
    getField("cb0").checkThisBox(0,true);
}
    else if(event.target.value!=="Yes"){
     getField("cb0").checkThisBox(0,false);
      }
}

This topic has been closed for replies.
Correct answer try67

and yes cb1, cb2, .....cb100


Then use this code:

var allChecked = true;

for (var i=1; i<=100; i++) {

    var f = this.getField("cb"+i);

    if (f.valueAsString=="Off") {

        allChecked = false;

        break;

    }

}

this.getField("cb0").checkThisBox(0, allChecked);

1 reply

try67
Community Expert
Community Expert
March 27, 2018

- You can't define variables with just numbers. How would it know if you're referring a number or the variable?

- You don't need the for-loop.

- Where did you place this code? Why are you accessing the field's value?

Here's how to do it properly. Create a (hidden) text field and apply this code as its custom calculation script:

var v1 = this.getField("cb1").valueAsString;

var v2 = this.getField("cb2").valueAsString;

var v3 = this.getField("cb3").valueAsString;

this.getField("cb0").checkThisBox(0, v1!="Off" && v2!="Off" && v3!="Off");

Participating Frequently
March 27, 2018

I only tired. I just want, that one checkbox activate automatically, as soon as the other 100 checkboxes are checked

Participating Frequently
March 27, 2018

Atomatically check a checkbox if a group of others are checked