Expand my Community achievements bar.

SOLVED

Single checkbox value based on array of checkboxes

Avatar

Level 2

i have a form with a number of checkboxes (let’s call them A, B, and C).

I am looking for a script which will enable a fourth checkbox (checkbox D) to be turned on if any and all of checkboxes A, B, or C are checked. And also turned back off if checkboxes A, B, or C are subsequently unchecked.

seems to be a deceptively simple task.

thank you so much in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 2

I got it.

As the checkboxes were in a table, I had to drill down a little farther. The name of the object alone didn't work.

Also, I didn't explain it particularly well the first time. I needed any combination of checkboxes A through C to create a positive result in checkbox D.

I was able to modify the string slightly and it worked perfectly.

if(Page2.Table3Sec1.Row2.cb16.rawValue == "1" | Page2.Table3Sec1.Row8.cb26.rawValue == "1" | Page2.Table3Sec1.Row10.cb62.rawValue == "1") //if cb16 OR cb26 OR cb62 is checked, check cbNV3
{
Page5.Table4Sec3_1.Table4Sec3_1_Row3.cbNV3.rawValue = "1";
}

if(Page2.Table3Sec1.Row2.cb16.rawValue == "0" & Page2.Table3Sec1.Row8.cb26.rawValue == "0" & Page2.Table3Sec1.Row10.cb62.rawValue == "0") //if cb16 OR cb26 OR cb62 is unchecked, uncheck cbNV3
{
Page5.Table4Sec3_1.Table4Sec3_1_Row3.cbNV3.rawValue = "0";
}

I cannot thank you enough.

View solution in original post

5 Replies

Avatar

Level 7

Hi originalien​,

In the change event (javascript) for the A, B and C checkboxes add the code:

if(CheckBoxA.rawValue == "1" & CheckBoxB.rawValue == "1" & CheckBoxC.rawValue == "1") //if A, B and C are checked. Check D
{
CheckBoxD.rawValue = "1";
}

if(CheckBoxA.rawValue == "0" | CheckBoxB.rawValue == "0" | CheckBoxC.rawValue == "0") //if A, B OR C are unchecked, uncheck D
{
CheckBoxD.rawValue = "0";
}

1609150_pastedImage_3.png

1609141_pastedImage_0.png

D is checked when all others are checked

1609148_pastedImage_1.png

If any of the A, B or C boxes are not checked. D is unchecked.

1609149_pastedImage_2.png

Avatar

Level 2

First and foremost, thank you a great deal for your prompt response.

Tantalizingly close.

Per request, I've utilized the script in the checkboxes (changed the names, of course) to no avail. A couple of questions:

I tested your script in a brand new one page document. It worked, as advertised. But, in my form the checkboxes appear on different pages. AND they appear within a table. Does that make it hairier?

Also, I don't think I explained it appropriately. In your script, all three checkboxes have to be checked in order to produce a positive result in the fourth checkbox. However, I want any combination of those three to produce a positive result. I tried using the OR string below to no avail.

What am I doing wrong?

if(cb16.rawValue == "1" | cb26.rawValue == "1" | cb62.rawValue == "1") //if cb16 OR cb26 OR cb62 is checked, check cbNV3
{
cbNV3.rawValue = "1";
}

if(cb16.rawValue == "0" | cb26.rawValue == "0" | cb62.rawValue == "0") //if cb16 OR cb26 OR cb62 is unchecked, uncheck cbNV3
{
cbNV3.rawValue = "0";
}

(BTW... did I say thank you for the prompt response? I can't tell you how helpful this is)

Avatar

Level 2

Standby... by jove, I think I've got it.

(Yes... it does matter that it's inside a table... I wasn't specifying the table AND the object name)

Avatar

Correct answer by
Level 2

I got it.

As the checkboxes were in a table, I had to drill down a little farther. The name of the object alone didn't work.

Also, I didn't explain it particularly well the first time. I needed any combination of checkboxes A through C to create a positive result in checkbox D.

I was able to modify the string slightly and it worked perfectly.

if(Page2.Table3Sec1.Row2.cb16.rawValue == "1" | Page2.Table3Sec1.Row8.cb26.rawValue == "1" | Page2.Table3Sec1.Row10.cb62.rawValue == "1") //if cb16 OR cb26 OR cb62 is checked, check cbNV3
{
Page5.Table4Sec3_1.Table4Sec3_1_Row3.cbNV3.rawValue = "1";
}

if(Page2.Table3Sec1.Row2.cb16.rawValue == "0" & Page2.Table3Sec1.Row8.cb26.rawValue == "0" & Page2.Table3Sec1.Row10.cb62.rawValue == "0") //if cb16 OR cb26 OR cb62 is unchecked, uncheck cbNV3
{
Page5.Table4Sec3_1.Table4Sec3_1_Row3.cbNV3.rawValue = "0";
}

I cannot thank you enough.

Avatar

Level 7

Good job in figuring it out.

You can also reference an object by using this.resolveNode. Using this, the form will search from top down for the first instance that matches. I have found there are times where a code isn't working for me and when i add the code it then works. Usually happens when working in a table. I usually just resolveNodes anyway now days just to save problems later. It isnt always required and depends on the size of your form.

eg: Page5.Table4Sec3_1.Table4Sec3_1_Row3.cbNV3.rawValue = "1"; would become

this.resolveNode("Page5.Table4Sec3_1.Table4Sec3_1_Row3.cbNV3").rawValue = "1";

Well done too on your commenting, you can never have too many comments. Sometimes i need to go back to a form months later and its great that i know what it does without having to browse the code to work it out.