Skip to main content
Known Participant
February 21, 2018
Answered

Checkbox to select and deselect other checkboxes

  • February 21, 2018
  • 1 reply
  • 12809 views

I am working on an Acrobat form which as four checkboxes. What I am trying to achieve are two things:

1. If any checkbox is selected, it selects all previous checkboxes.

2. If any checkbox is deselected, it deselects all following checkboxes, leaving the current and previous checkboxes selected.

Any assistance would be appreciated.

This topic has been closed for replies.
Correct answer Thom Parker

Thom

I found this script which I used in the mouse up for "Check Box18" which also selects "Check Box17" when checked.

I have also used this script for "Check Box19" (adding "Check Box18" to the var fn), and for "Check Box20" (adding "Check Box 18", "Check Box19" to the var fn). These are working fine for selecting the previous checkboxes, but I am having trouble incorporating a script which deselects Check Boxes 19 and 20 when "Check Box18" is deselected (same for "Check Box19" which deselects "Check Box20").

As a graphic designer scripting is a foreign language to me. The only script I am familiar with, is a font style!

this.calculate = false;

var fn = ["Check Box17"];

for (var i = 0; i < fn.length; i++) {

    if (this.getField(fn).type == "checkbox") {

        this.getField(fn).checkThisBox(0, true) ;

    }

}

this.calculate = true;

this.calculateNow();


Don't use that script, it makes no sense.

Here is the MouseUp script for Checkbox 18, all the others are variations on this,

if(event.target.isBoxChecked(0))

{// Perform actions when checked

   this.getField("Check Box17").checkThisBox(0,true);

}

else

{// Perform actions when unchecked

   this.getField("Check Box19").checkThisBox(0,false);

   this.getField("Check Box20").checkThisBox(0,false);

}

When you write out the description of what a checkbox will do you must include all actions, both checked and unchecked, all in one place.

1 reply

Thom Parker
Adobe Expert
February 22, 2018

This has been asked many times. Here's some search results from this forum:

https://forums.adobe.com/search.jspa?q=check+all

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
February 22, 2018

Thom,

I wasn't clear when I mentioned ALL previous and following checkboxes on the form, as I need to apply the check/uncheck to only four checkboxes out of a total of 83. They are labelled Check Box17, Check Box 18, Check Box19 and Check Box20.

So I need the following to happen:

If Check Box20 is selected, it also selects Check Boxes 17, 18 and 19

If Check Box19 is selected, it also selects Check Boxes 17 and 18

If Check Box18 is selected, it also selects Check Box17

In addition to the above, I need it to do this:

If Check Box17 is deselected, it also deselects Check Boxes18, 19 and 20

If Check Box18 is deselected, it also deselects Check Boxes19 and 20 (leaving Check Box17 selected)

If Check Box19 is deselected, it also deselects Check Box20 (leaving Check Box17 and 18 selected)

Thank you

Known Participant
March 7, 2018

So it needs to be reversed. Use this code to get the list

var aFldList = this.getField("Group1").getArray().sort(function(a,b){return a.name>b.name;});

Then you can use this list to get the text.

Actually if you are really ambitious, you could use this code to get the complete value in one line

event.value = this.getField("Group1").getArray().filter(function(a){return a.value !="Off";}.sort(function(a,b){return a.name>b.name;}).map(function(a){return a.value}).join("\n");

The code first filters the array to only include fields that are checked, then sorts the order, then creates an array of just the export values, and then joins them into a multiline string.


Thank you Thom.

Your solution above has solved my problem. Appreciate your time and patience in answering my query.