Skip to main content
Participant
Feb 6, 2025 5:37 PM UTC
Answered

Button to lock and unlock all form fields

Hello I created a button to lock all fields once pressed with the script.  When I press  it nothing happens.

 

// Lock all fields in the form
var allFields = this.getFieldNames();
for (var i = 0; i < allFields.length; i++) {
this.getField(allFields[i]).readonly = true;
}

 

Can someone help.? I would also need to unlock to make edits.

 

Thank you.

PDF Automation Station
Community Expert
Feb 6, 2025 6:50 PM UTC

Change the word true in the script to false.  You would have to exclude the unlocking button field from the original script or else it would be locked ("readonly") and wouldn't work.

8 replies

PDF Automation Station
Community Expert
Community Expert
Feb 6, 2025 5:44 PM UTC

this.getFieldNames() is not a function.  Try this:

for(var i = 0; i < this.numFields; i++)
{
var fieldName = this.getNthFieldName(i);
var oFld=this.getField(fieldName);
if(oFld==null){continue}
oFld.readonly=true;
}
Translate
tony_6388Author
Participant
Feb 6, 2025 5:55 PM UTC

That worked for locking thank you!!!!

If I wanted to put a button to unlock the fields, to make changes - what would I change?

 

Thank you.

Translate
PDF Automation Station
Community Expert
Community Expert
Feb 6, 2025 6:50 PM UTC

Change the word true in the script to false.  You would have to exclude the unlocking button field from the original script or else it would be locked ("readonly") and wouldn't work.

Translate
Bernd Alheit
Community Expert
Community Expert
Feb 6, 2025 5:42 PM UTC

Check the Javascript console for errors. getFieldNames is not a function of Acrobat.

Translate