Skip to main content
Inspiring
November 25, 2020
Answered

Conditional Formatting for multiple checkboxes, into one

  • November 25, 2020
  • 2 replies
  • 4460 views

Hello all,

 

So if necessary, since I know I can get a little long winded I put a tl:dr at the end. Thanks for your patience if you read all the way through!!

 

I am working on modifying/improving a pdf form utilizing checkboxes that would communicate to other checkboxes, where the other checkboxes provide a total score. This is for conducting an evaluation on a given process.... What I'm trying to do is get a script so that if there are 5 requirements that need to be met just to receive the check that indicates pass instead of fail (multiple pass/fail events across the board). The trick is, if just any one of the 5 requirements is missed the check is not received, indicating that the entire event is failed. I'm hoping this is a clear enough scenario for someone to provide a base script that I can integrate, and maybe even build off of. I can read java, but have a hard time building without a base. Any help is greatly appreciated, and thanks in advance!!

 

tl:dr

trying to obatin a base script for making five checked checkboxes cause a sixth to check, with one stipulation; if any one of the five checkboxes are not checked, the sixth checbox will not get checked. Sidenote: can read and build off javascript, but novice enough where I can't create without a base script.

This topic has been closed for replies.
Correct answer Nesa Nurani

I want it to automatically check Check Box3, only if Check 1-8 are checked.


Then use this code and put in in every checkbox 1-8

var c1 = this.getField("Check 1").valueAsString;
var c2 = this.getField("Check 2").valueAsString;
var c3 = this.getField("Check 3").valueAsString;
var c4 = this.getField("Check 4").valueAsString;
var c5 = this.getField("Check 5").valueAsString;
var c6 = this.getField("Check 6").valueAsString;
var c7 = this.getField("Check 7").valueAsString;
var c8 = this.getField("Check 8").valueAsString;
var c9 = this.getField("Check Box3");
if(c1 != "Off" && c2 != "Off" && c3 != "Off" && c4 != "Off" && c5 != "Off" && c6 != "Off" && c7 != "Off" && c8 != "Off"){
c9.value = "Yes";}
else c9.value = "Off";

2 replies

AcredeauxAuthor
Inspiring
November 25, 2020

Update: the amount of checkboxes that trigger the one to become checked is 8

Nesa Nurani
Community Expert
Community Expert
November 25, 2020

One option is to make a hidden text field to use code in it as "Custom Calculation Script".
Lets say your checkboxes are named Check Box1 to Check Box6,
you can use code like this in hidden text field:

var check = "";
for (var i=1; i<=5; i++) {
if (this.getField("Check Box"+i).valueAsString != "Off")check++}
this.getField("Check Box6").value = check == 5 ? "Yes" : "Off";

Where "Yes" is an export value of "Check Box6" in case you change it to something else.

 

Alternative to above is to use code in all 5 checkboxes as Mouse Up event like this:

var c1 = this.getField("Check Box1").valueAsString;
var c2 = this.getField("Check Box2").valueAsString;
var c3 = this.getField("Check Box3").valueAsString;
var c4 = this.getField("Check Box4").valueAsString;
var c5 = this.getField("Check Box5").valueAsString;
var c6 = this.getField("Check Box6");
if(c1 != "Off" && c2 != "Off" && c3 != "Off" && c4 != "Off" && c5 != "Off"){
c6.value = "Yes";}
else c6.value = "Off";

Rename fields if necessary.

 

ls_rbls
Community Expert
Community Expert
November 25, 2020

++Adding to the discussion,

 

Or you can also add this line to every checkbox except for "Check Box6":

 

var ck = this.getField("Check Box6");

(event.target.value !== "Off") ?   ck.checkThisBox(0, true) :  ck.checkThisBox(0, false);

 

 

Nesa Nurani
Community Expert
Community Expert
November 25, 2020

That would check "Check Box6" when any check box is checked.

From my understanding OP want to check "Check Box6" only if all 5 are checked and not before.