Skip to main content
Participant
March 23, 2022
Question

Autocheck CheckBoxes

  • March 23, 2022
  • 2 replies
  • 718 views
If I have a checkbox , am I able to action the following.
 
if A1.1, A1.2 and A1.3 are all checked. then B1 (checkbox) automatically checked at the moment
I think it required Javascript.
 
Thank You
This topic has been closed for replies.

2 replies

bebarth
Community Expert
Community Expert
March 24, 2022

...or a bit shorter for the function:

 

function checkAllA1() {
	this.getField("B1").checkThisBox(0, this.getField("A1.1").value!="Off" && this.getField("A1.2").value!="Off" && this.getField("A1.3").value!="Off");
}

 

and that also works with the BarlaeDC's isBoxChecked properties:

 

function checkAllA1() {
	this.getField("B1").checkThisBox(0, this.getField("A1.1").isBoxChecked(0) && this.getField("A1.2").isBoxChecked(0) && this.getField("A1.3").isBoxChecked(0));
}

 

 @+

BarlaeDC
Community Expert
Community Expert
March 24, 2022

Hi,

 

You create a global function by searching for "JavaScript" in the tools and selecting "Document JavaScripts" and then enter "checkAllA1".

 

This will open a dialog with the following code in it:

fucntion checkAllA1() {

}

 

in between the curly brackets you can add this code

function checkAllA1 (){
    // get if the A1 fields are checked
    var chkA1One = this.getField("A1.1").isBoxChecked(0);
    var chkA1Two = this.getField("A1.2").isBoxChecked(0);
    var chkA1Three = this.getField("A1.3").isBoxChecked(0);
    // default to B not being checked
    var checkB = false;

    // if all three A1 checkboxes are checked
    if ( chkA1One  && chkA1Two && chkA1Three){
        // set checkB to true
        checkB = true;
    } 
    // check or uncheck B as required
    this.getField("B1").checkThisBox(0, checkB);
}

 click "OK"

 

Then on each of the A1 fields add the following code as a "mouse up" event

 

checkAllA1();

 

Hope that helps