Skip to main content
Participating Frequently
July 2, 2023
Answered

Clear button for specific checkboxes in a form

  • July 2, 2023
  • 2 replies
  • 1231 views

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!

This topic has been closed for replies.
Correct answer Thom Parker

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

 

 

 

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
July 2, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
July 3, 2023

Thanks! That worked like a charm!

try67
Community Expert
Community Expert
July 2, 2023

Try this:

 

for (var i = 0; i <=4; i++) {
    var f = this.getField("Potential"+i);
	f.value = "Off";
}