Copy link to clipboard
Copied
Hi,
I have some 50-60 page document and i want to check all checkboxes using one single script.. How can i do that?
Thank you
Copy link to clipboard
Copied
If they are all individual fields then it's quite easy to do, actually. You don't need to sort them or anything like that. Just change this line:
if (f.type=="checkbox") f.checkThisBox(0, true);
To this:
if (f.type=="checkbox" && f.page<=4) f.checkThisBox(0, true);
Copy link to clipboard
Copied
You can do it using this code:
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f==null) continue;
if (f.type=="checkbox") f.checkThisBox(0, true);
}
Copy link to clipboard
Copied
P.S -Let's say i want to limit it to page 1-5, can i do that?
Copy link to clipboard
Copied
Yes, but are they all individual fields, or are some part of a group?
Copy link to clipboard
Copied
Individual fields...
Copy link to clipboard
Copied
Trying to sort on page number is not a great idea. Instead, use field group naming. This will make everything easier.
For example: "Group1.Chk1", "Group1.Chk2", "Group1.Chk3", "Group1.Chk4",
You control which fields are in the group with the names.
If the group only contains checkboxes then this one line script will reset them all at once.
this.resetForm("Group1");
This script will check them all.
this.getField("Group1").getArray().forEach(a=>a.value = a.exportValues[0];);
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you for the script but my work flow requires limiting script to page rank....how can i do that(let's say page 5-10)?
Copy link to clipboard
Copied
In Acrobat JavaScript, field objects have a page property. If there is only one field on in the document with a particular field name, this property is an integer indicating the 0 based page number. However, it's not that simple because fields with the same name can be on many different pages. Also some fields naturally have more instances, such as radio buttons. In these cases the field page property is an array of page numbers. That's all you need to know to figure out what pages a particular field is on.
This code returns true if if a field is in a page range. Specifically on page 1 to 5.
var nPgMin = 0, nPgMax = 4;
var oFld = this.getField("xxx");
var aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
var bOnPage = aPgs.some(a=> a>=nPgMin && a<=nPgMax);
It can easily be integrated in the code provided by Try67 for testing all fields on the PDF.
You might also be interested in the answer I provided here:
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
this is the code that i typed
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if (f==null) continue;
if (f.type=="checkbox") f.checkThisBox(0, true);
var nPgMin = 0, nPgMax = 4;
var oFld = this.getField("xxx");
var aPgs = (typeof(oFld.page) == "number")?[oFld.page]:oFld.page;
var bOnPage = aPgs.some(a=> a>=nPgMin && a<=nPgMax);
}
this doesn't seem to work.please help
Copy link to clipboard
Copied
If they are all individual fields then it's quite easy to do, actually. You don't need to sort them or anything like that. Just change this line:
if (f.type=="checkbox") f.checkThisBox(0, true);
To this:
if (f.type=="checkbox" && f.page<=4) f.checkThisBox(0, true);

