Skip to main content
dennisg19059968
Participating Frequently
November 22, 2017
Answered

Select and Deselect All Checkboxes

  • November 22, 2017
  • 2 replies
  • 6283 views

Hi,

I'm using Adobe acrobate dc.

I have three checkboxes in my pdf-document.

They are namned: checkbox1, checkbox2 and checkbox3

I wish the following to happen:

-When checkbox1 is selected, checkbox2 and checkbox3 also become selected.

-When checkbox1 is deselected, checkbox2 and checkbox3 also become deselected.

I'm more than a beginner to this with javascript, so please keep this in mind when

explaining or giving me a working javascript.

Thanks

/Dennis

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

By select, do you mean checked? Selected means the field has keyboard focus.

Put your script on the MouseUp event for "checkbox1". All you need to do is set the value of the other checkboxes to the value of "checkbox1", which is "event.target.value.

So the line of code for setting "checkbox2" is:

this.getField("checkbox2").value = event.target.value;

So what happens when the user changes the value of "checkbox2"? Does it affect other fields?

2 replies

Inspiring
November 23, 2017

The following script will check the other 2 check boxes if box 1 is checked and uncheck them when box 1 is unchecked and it does not even need to know the value of the checked boxes.

// mouse up action JavaScript;

// get field objects;

var CB1 = this.getField("checkbox1");

var CB2 = this.getField("checkbox2");

var CB3 = this.getField("checkbox3");

// check check box 1 value;

if(CB1.value != "Off")

{

// check the ohter boxes;

CB2.checkThisBox(0,true);

CB3.checkThisBox(0,true);

} else {

// uncheck the other boxes;

CB2.checkThisBox(0, false)

CB3.checkThisBox(0, false);

}

Thom Parker
Community Expert
Community Expert
November 23, 2017

Got a lot of code there, why so much?

BTW: I corrected my previous post to use the correct event property for getting the value. It only takes two lines of code.  And it could be modified to use the "checkThisBox()" function if you wanted to avoid handling the export values.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
dennisg19059968
Participating Frequently
November 23, 2017

Thank you Thom, the code

this.getField("checkbox2").value = event.target.value;

works fine and does its job.

As I'm a beginner of coding javascript and want to use this type of checkbox function on many locations and pages in my form, I would like to know what are the advantages and disadvantages of using export values instead of modifing it to use the "checkThisBox" instead?

Thanks a lot again!

/Dennis

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 23, 2017

By select, do you mean checked? Selected means the field has keyboard focus.

Put your script on the MouseUp event for "checkbox1". All you need to do is set the value of the other checkboxes to the value of "checkbox1", which is "event.target.value.

So the line of code for setting "checkbox2" is:

this.getField("checkbox2").value = event.target.value;

So what happens when the user changes the value of "checkbox2"? Does it affect other fields?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often