These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

(de)select all checkboxes

moonglow
Registered: Jun 7 2008
Posts: 10

This seems a ridiculous request, but I can't work out how to set the value (check) a series of checkboxes.

I've got a pdf with a series of layers (map items). I've created a series of checkboxes alongside the legend (Check_Box1, Check_Box2 etc). Selecting these checkboxes turn on and off the respective layers on the map - all works fine.

I just added the checkboxes using the forms tool, so I'm not sure that they are part of a form as such.

I've also made a couple of buttons that turn off all layers (well most, it leaves the map outline and legend etc there) and one that turns it all back on. All works, all good.

The only thing I can't work out how to do is to uncheck all the legend item checkboxes when the All Off button is pressed (using mouseup) and check them all when the All On button is pressed.

Would appreciate any help, thanks heaps!

Dean

My Product Information:
Acrobat Pro 8.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
To clear the checked butotns, you can make a button and use JavaScirpt to reset the form, add a script to set each buttons' to a value of "Off", or

To turn the buttons on, you could write some JavaScript to set each button's value to the export value of the button.

Or to toggle the buttons with one push button one could use the "isBoxChecked" propety to see if a button is checked or not then either set the button's value to "Off" of the "exprotValue'.

George Kaiser

moonglow
Registered: Jun 7 2008
Posts: 10
Thanks gkaiseril, the Javascript option would be my preference, then I can just add it to the existing script I've got.

Do you have any ideas of what the script would look like?

i.e. could I just go

Check_Box1.exprotValue = "Off";
Check_Box2.exprotValue = "Off";
Check_Box3.exprotValue = "Off";
etc

?

and = "On" for the reverse?
moonglow
Registered: Jun 7 2008
Posts: 10
... just tried it and get these errors in the console..

off:Annot1:OnFocus:Action1Exception in line 2 of function top_level, script AcroForm:All Layers off:Annot1:OnFocus:Action1

ReferenceError: Check_Box1 is not defined
2:AcroForm:All Layers off:Annot1:OnFocus:Action1
ReferenceError: Check_Box1 is not defined
3:AcroForm:All Layers off:Annot1:OnFocus:Action1Exception in line 3 of function top_level, script AcroForm:All Layers off:Annot1:OnFocus:Action1

ReferenceError: Check_Box1 is not defined
3:AcroForm:All Layers off:Annot1:OnFocus:Action1


The script I'm using is pretty inefficient, but up to now had been doing the job, .. here is an abreviated version of the select all off button script ...

var docOCGs = this.getOCGs();

Check_Box1.exprotValue = "Off";

for (var x=0; x < docOCGs.length; x++)
{
if(docOCGs[x].name == "CAU06 NZDep (Christchurch)")
{
docOCGs[x].state = false;}
if(docOCGs[x].name == "CAU06 NZDep (SI)")
{
docOCGs[x].state = false;
}
if(docOCGs[x].name == "Anno Public Health (Christchurch)")
{
docOCGs[x].state = false;
}
}
moonglow
Registered: Jun 7 2008
Posts: 10
I've gotten a bit further, I can deselect all the checkboxes through

var Chk_Box1 = this.getField("Check_Box1");
var Chk_Box2 = this.getField("Check_Box2");

Chk_Box1.value = 0;
Chk_Box2.value = 0;

I've tried = 1 = "on" = true but I can't seem to re-check them for the select all.

Sorry for being so painful, its been a very long time since I had to do any scripting.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
There are so many solutions.

The easiest assuming there are no other form fields:

this.resetForm(); // reset form

Or you want to name the fields t reset:

this.resetForm(["Chk_Box1", "Chk_Box2", "Chk_Box3"]); // reset named fields

Or using single lines of code for each box:

// force field to be unchecked
this.getField("Chk_Box1").value = "Off"; // turn off field
this.getField("Chk_Box2").value = "Off"; // turn off field
this.getField("Chk_Box3").value = "Off"; // turn off field

or selectively

// if field is checked turn it off
if(this.getField("Chk_Box1").value == "Yes") this.getField("Chk_Box1").value = "Off";
// if field is checked turn it off
if(this.getField("Chk_Box2").value == "Yes") this.getField("Chk_Box2").value = "Off";
// if field is checked turn it off
if(this.getField("Chk_Box3").value == "Yes") this.getField("Chk_Box3").value = "Off";

George Kaiser

moonglow
Registered: Jun 7 2008
Posts: 10
Thanks gkaiseril, it was the "off" and "yes" that I needed. Why they wouldnt use the same construct (Yes/No or Off/On) I'll never know! :)

Thanks