Skip to main content
Inspiring
June 20, 2025
Answered

Loop Through Specific Array of Fields (and perform any code)

  • June 20, 2025
  • 3 replies
  • 496 views

I have 100 test fields (test01, test02.....test100).

 

When test signature is signed, lock all the test fields.  Unlock when signature is cleared.

 

Can't figure out what I am doing wrong.

    for (var i=1; i<=100; i++)
        var num = (i < 10 ? "0" + i : i);
        var field = getField("Test" + num);

        if(getfield("Test Signature").value == "")
            field.readonly = false

        else
            field.readonly = true

 

Correct answer MBChels

Omg....(face smack).

    for (var i=1; i<=100; i++){
        var num = (i < 10 ? "0" + i : i);
        var field = getField("Test" + num);

        if(getField("Test Signature").value == "")
            field.readonly = false

        else
            field.readonly = true
}

 

3 replies

MBChelsAuthorCorrect answer
Inspiring
June 20, 2025

Omg....(face smack).

    for (var i=1; i<=100; i++){
        var num = (i < 10 ? "0" + i : i);
        var field = getField("Test" + num);

        if(getField("Test Signature").value == "")
            field.readonly = false

        else
            field.readonly = true
}

 

try67
Community Expert
Community Expert
June 20, 2025

- You need to put curly brackets around all the code that you want to associate with the loop.

- You need to use getField, not getfield.

Thom Parker
Community Expert
Community Expert
June 20, 2025

:), there are of course a number of syntax issues.  

Another way to do this would be to put all the code into the signing event, and not use a calculation event at all. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
MBChelsAuthor
Inspiring
June 20, 2025

I will mess around with this and let you know!

Thom Parker
Community Expert
Community Expert
June 20, 2025

Where is this script placed?

 

The best way to test whether or not a signature field has been singned is with the "SignatureValidate" function. 

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#id654

 and the best place to test this sort of thing is on the signing event. 

 

However,  the very best way to lock fields when the field is signed is to use the "Lock Fields" option on the signature field properties dialog, on the "Signed" tab.

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
MBChelsAuthor
Inspiring
June 20, 2025

It is in calculation field because I have other script that 'executes when field is signed'.  I thought the 'signed' tab only handles one way and wouldn't do the opposite once the signature is cleared hence why I put it in a calculation field?

Thom Parker
Community Expert
Community Expert
June 20, 2025

The "Lock on Signed" action is one of the field actions that is not implemented with a script. It's a real built-in PDF action, that's in the PDF Specification. And it works both ways. This also means that it should work on viewer that do not support scripting, but I wouldn't count on it. 

 

I think you would be better served by locking the fields with the "Lock on Signed" action and doing the other stuff in the calculate script. Use the "SignatureValidate" function to determine signing status. 

 

 

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