5 Replies Latest reply on Feb 22, 2018 7:32 AM by try67

    Lock/Unlock Button - Password Sync Issues


      Hi all,


      Need some help from someone who knows their stuff...


      I've got a Interactive PDF that has a script set to a button where it locks certain fields, unless you know the password to make all fields editable. It's the same script that's on this help forum elsewhere. I need to take it a step further however, but I don't know how. I get the general gist of what I need to do, just don't know how to execute it.


      My problem is my button has two states; a 'Locked' (red) state and 'Unlocked' (green) state. I need to know how to sync up the code so that if you click the button to unlock, then cancel the password prompt, that the button doesn't continue to switch to the 'unlock' state with it still being locked.


      For example;

      • the button is currently red (locked)
      • you click the button to unlock, and the password prompt box comes up
      • you cancel that prompt
      • the button then switches to show the green (unlocked) state, even though it is still locked.


      Is there a way to edit the script (below) so that it always knows what state the button is in, and reacts accordingly. So in the locked state, always asks for the password and in the unlocked state always locks the fields?


      Any help would be great,





      The script i'm using is as follows:


      (function () {


          // Prefix for group field names. Change to match what you want to use.

          // Rename the fields you want to lock to match this prefix (e.g., "PRIV.NAME")

          var f_prefix = "PRIV";


          // Your chosen password goes here

          var pw = "1234";


          // Get a reference to the first field in the group

          var f = getField(f_prefix).getArray()[0];


          //Determine new readonly state, which is the opposite of the current state

          var readonly = !f.readonly;

          var readonly_desc = readonly ? "lock" : "unlock";


          //Prompt user for the password only if unlocking

         if (f.readonly) {

          var resp = app.response({

              cQuestion: "To " + readonly_desc + " the fields, enter the password:",

              cTitle: "Enter password",

              bPassword: true,

              cLabel: "Password"


         } else {

             var resp = pw;



          switch (resp) {

          case pw:

              getField(f_prefix).readonly = readonly;

              app.alert("The fields are now " + readonly_desc + "ed.", 3);


          case null:  // User pressed Cancel button


          default:  // Incorrect password

              app.alert("Incorrect password.", 1);





        • 1. Re: Lock/Unlock Button - Password Sync Issues
          try67 MVP & Adobe Community Professional

          You say that the button has two states, but I don't see anywhere in the code where you change from one state to the other, so how is it done?

          • 2. Re: Lock/Unlock Button - Password Sync Issues
            mattd11018621 Level 1

            Hi Try67,


            That's my issue I don't know what code to place and where, as I'm learning as I go along!


            Let's for arguments sake say my button is called 'Unlock_Button' and has two states. How could I modify the javascript to include the button?


            Currently I have the button set-up in indesign, and adding the code to it in Acrobat.



            • 3. Re: Lock/Unlock Button - Password Sync Issues
              Test Screen Name Most Valuable Participant

              Acrobat doesn’t have multistate buttons. Two popular tricks to seem to do this are


              1. Two buttons in the same space. You arrange (in your code) that one is always visible and one is always Hidden. Recommended. 


              2. Loading separate images as icons. Best avoided if you are new to this.


              If InDesign makes multistate buttons it will probably be doing something clever and too complicated to follow and adapt.


              If you don’t know WHERE to put code it means you don’t understand the flow of the code. You absolutely need this before you can adapt even if you don’t follow every line in it. Focus on understanding the flow next. Especially work on pairing up braces {...}

              • 4. Re: Lock/Unlock Button - Password Sync Issues
                George_Johnson MVP & Adobe Community Professional

                I agree that you shouldn't bother to set up different button states in InDesign, and instead create the button in Acrobat. With JavaScript you can change various properties such as button label and background color. If you explain in more detail how you want the button to change when the fields are locked/unlocked we can provide more guidance.

                • 5. Re: Lock/Unlock Button - Password Sync Issues
                  try67 MVP & Adobe Community Professional

                  Here's a simple example of how to create a two-state button in Acrobat.

                  Enter this code as your button's Mouse Up event:


                  if (event.target.buttonGetCaption()=="LOCKED") {
                      event.target.fillColor = color.green;
                  } else {
                      event.target.fillColor = color.red;