4 Replies Latest reply on Aug 24, 2010 2:08 PM by ksumwalt

    File variable

    ksumwalt

      I am looking to define a temporary variable in an Acrobat Form, which is specific to the file only, but can't find anything.  I am looking for something similar to a Global variable, but not available across documents.  I could create a text field that is hidden and does not print, but I was hoping for something cleaner.  Is there a form level variable?

       

      Regards,

      Karl

        • 1. Re: File variable
          George_Johnson MVP & Adobe Community Professional

          If you create a document-level JavaScript and declare a variable (outside of a function definition), it will have document-level scope.

           

          var mydocvar = "Jimmy Buffett";

          1 person found this helpful
          • 2. Re: File variable
            ksumwalt Level 1

            OK, so I have tried the following to declare a variable outside of a function definition in the JavaScript Functions dialog that opens with the  Advanced->Document Processing->Document Javascripts menu option:

            Define a name, Karl, and put the declaration in front of the function:

            var formVariable = "";

             

            function Karl()

            {

            var formVariable = "";

            }

            I have also just put the decloration in, then removed the () generated:

            Put var formVariable = "" in for the Script Name, get

            function var formVariable = ""()

            {

            }

            Change it to:

            var formVariable = ""

            or:

            var formVariable = "";

             

             

            And none of this work.  The variable does not seem to be defined when I try to display it with:

            app.alert(formVariable, 1, 2);

             

            I am sure I am missing something, so how do I define the variable outside a function?  (Note, the function Karl() would be used to reset the variable, and other things as well, I took the rest out for clarity.

            • 3. Re: File variable
              George_Johnson MVP & Adobe Community Professional

              The last variable declaration you showed is correct. But note that you initialized the variable to a zero-length string, so your app.alert will not show anything.

               

              How about this:

               

              var formVariable = "Hello";

               

              and then, place the following code in the MouseUp event of a button:

               

              app.alert(formVariable, 2, 1);

               

              and press the button.

               

              Does that work?

               

               

              BTW, variables declared within a function are local to that function. So to reset the variable, the function would look like:

               

              function Karl() {

               

                  formVariable = "";

              }

              • 4. Re: File variable
                ksumwalt Level 1

                It seems there was another error in code, where I put a ; at the end of the closing parenthesis for an if statement:

                     if (true);

                          {

                          };

                It didn't work, so I thought the variable was not being saved.  I fixed this just before your last response.

                 

                Thank you for the help!

                 

                Karl