Expand my Community achievements bar.

IF statement for ALL checkboxes

Avatar

Former Community Member
JavaSCript-IF statement for all checkboxes:



I have

Subform1 with

CheckBox1

CheckBox2

CheckBox3



Subform2 with

StaticText



I make Subform2 hidden and the following text works as I want.



if (this.rawValue == 1)

{

Subform2.presence = "visible";

}

else

{

Subform2.presence = "invisible";

}



But how do I create script, that if ONLY, all of the checkboxes are selected, the hidden text in Subform2 becomes visible?
6 Replies

Avatar

Level 7
Logically and all the comparisons of the check boxes being equal to a given value:



// logically "and" all the individual check boxes being equal to provided value for that check box

var bResult = (CheckBox1 == 1); // logical value of check box 1

bResult = bResult and (CheckBox2 == 1); // logical value of check box 2

bResult = bResult and (CheckBox3 == 1); // logical value of check box 3

if(bResult) {

Subform2.presence = "visible"; // all check boxes had value 1

} else {

Subform2.presence = "invisible"; // at least one box was not equal 1

}



or



if( (CheckBox1 == 1) and (CheckBox2 == 1) and (CheckBox3 == 1) ) {

Subform2.presence = "visible"; // all check boxes had value 1

} else {

Subform2.presence = "invisible"; // at least one box was not 1

}

Avatar

Former Community Member
Geo, thank you for the quick response.



When I do just one checkbox, I do it for the click event



but I am not understanding where/how to do your code?

Avatar

Level 7
You can either add it to every check box's click event or write a document level function (so all the code is in one location) and then call that function in every check box's click event.

Avatar

Former Community Member
HELP: I thought I would finally understand but I don't.



This works for one checkbox:



----- form1.#subform[1].sf1.cbx1::click: - (JavaScript, client)

if (cbx1.rawValue == 1)

{

sf2.presence = "visible";

}

else

{

sf2.presence = "invisible";

}



But this doesn't:

----- form1.#subform[1].sf1.cbx1::click: - (JavaScript, client)



if ((cbx1.rawValue == 1)& (cbx2.rawValue == 1)& (cbx3.rawValue == 1)

{

sf2.presence = "visible";

}

else

{

sf2.presence = "invisible";

}



Could you post an example?

Avatar

Former Community Member
HELP: I thought I would finally understand but I don't.



This works for one checkbox:



----- form1.#subform[1].sf1.cbx1::click: - (JavaScript, client)

if (cbx1.rawValue == 1)

{

sf2.presence = "visible";

}

else

{

sf2.presence = "invisible";

}



But this doesn't:

----- form1.#subform[1].sf1.cbx1::click: - (JavaScript, client)



if ((cbx1.rawValue == 1)& (cbx2.rawValue == 1)& (cbx3.rawValue == 1))

{

sf2.presence = "visible";

}

else

{

sf2.presence = "invisible";

}



Could you post an example?

Avatar

Former Community Member
Never mind. I was missing a parentheses to enclose the nested statement.