Search code examples
javascriptcheckboxadobeacrobat

Acrobat javascript to check muliple checkboxes with one click?


I have about 60 checkboxes in a document. I am trying to set it up so that there is one 'master' checkbox so that if that one checkbox is checked, they all become checked.

My boxes are named checkbox.0, checkbox.1, checkbox.2, etc.

My javascript is run on mouse up and is:

var f = this.getField("checkbox");
f.checkThisBox(0,true);

Which does nothing. If I add a '.0' to the end of 'checkbox', it will check box checkbox.0:

var f = this.getField("checkbox.0");
f.checkThisBox(0,true);

This works, but I want to check ALL the checkboxes.


Solution

  • You would loop through the checkboxes, and check them. Roughly, your code would look like

    for (var i = 0 ; i <= 60 ; i++) {
    this.getField("checkbox." + i).checkThisBox(0, true) ;
    }
    

    And that should do it. If the return value of those boxes is all the same (for example "Yes"), this approach:

    for (var i = 0 ; i <= 60 ; i++) {
    this.getField("checkbox." + i).value = "Yes" ;
    }
    

    This second approach would also be used to uncheck the boxes, just use "Off" as value.

    The checkThisBox() method applies only to one single field, as well as the value property. This means, hierarchical fieldnames do not provide any advantages here (they do with other properties, but not with what we have here).