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

Clear button for specific checkboxes in a form

Community Beginner ,
Jul 02, 2023 Jul 02, 2023

Hello.

 

I am new to Javascript in PDF documents.

I have a form with multiple checkboxes set in specific areas.

I created a button that I want to uncheck all buttons in a specific area.

I named the buttons "Potential#0-4" (Potential1, Potential2, etc.).

I found a javascript that I wanted to change all Checkboxes to "unchecked" when clicked (mouse up), but when I press the button, nothing happens:

function unCheckAll () {
var oAll = this.getField("Potential");
var aAll = oAll.getArray();
for(var i = 0; i < aAll.length; i++)
{
aAll.value = "Off";
}
}

unCheckAll();

 How can I make the button uncheck all checkboxes with "Potential" in their name?

 

Thank you!

TOPICS
How to , JavaScript , PDF
965
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 ,
Jul 02, 2023 Jul 02, 2023

To use the "getArray()" function the fields must be named using group notation. 

For example:"Potential.check1", "Potential.check2", etc.

Do this and then you can use this one line of code to reset the checkboxes

 

this.resetForm("Potential");

 

 

 

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

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 ,
Jul 02, 2023 Jul 02, 2023

Try this:

 

for (var i = 0; i <=4; i++) {
    var f = this.getField("Potential"+i);
	f.value = "Off";
}
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 ,
Jul 02, 2023 Jul 02, 2023

To use the "getArray()" function the fields must be named using group notation. 

For example:"Potential.check1", "Potential.check2", etc.

Do this and then you can use this one line of code to reset the checkboxes

 

this.resetForm("Potential");

 

 

 

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
Community Beginner ,
Jul 03, 2023 Jul 03, 2023

Thanks! That worked like a charm!

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 ,
Sep 10, 2024 Sep 10, 2024

Hi Thom, I've just used this and it works - however I need the checkbox to stay ticked or on when selected. So it resets the other checkboxes in the group, but itself is checked (like a "none of the above" option). What code can be added here to this? Thank you 

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 ,
Sep 10, 2024 Sep 10, 2024

Make the "None of the Above" checkbox the default. Then it will be checked when the fields are reset. 

 

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 ,
Sep 10, 2024 Sep 10, 2024
LATEST

Within the group of checkbox I have to limit selection to 3 maximum, so when I make "None of the above" the default, this counts towards the three. Can you think of anyway to get around this? I.e. Three options are selected, then None is selected, and the three options clear. OR, None is selected, then another option is selected, and None clears. 

 

This is what I'm using to limit the selections: 

var nMax = 3;
if(event.target.value != "Off")
{
var nCnt = 0;
this.getField("ASix").getArray().forEach(function(a){if(a.value != "Off") nCnt++;});
if(nCnt > nMax)
event.target.value = "Off";
}

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