Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to check all checkboxes at once in a given document

New Here ,
Oct 21, 2022 Oct 21, 2022

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

TOPICS
How to , JavaScript , PDF forms
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Oct 22, 2022 Oct 22, 2022
LATEST

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);

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2022 Oct 21, 2022

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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2022 Oct 21, 2022

P.S -Let's say i want to limit it to page 1-5, can i do that?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2022 Oct 21, 2022

Yes, but are they all individual fields, or are some part of a group?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2022 Oct 21, 2022

Individual fields...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2022 Oct 21, 2022

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];);

 

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2022 Oct 21, 2022

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)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2022 Oct 21, 2022

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:

https://community.adobe.com/t5/acrobat-discussions/reset-only-page-1-with-a-poppup/m-p/13286650#M384...

 

 

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2022 Oct 22, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2022 Oct 22, 2022
LATEST

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines