These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Global Variables?

subieguy2
Registered: Apr 30 2009
Posts: 15

I am trying to pass a value from one script to another and am not very familiar with how to do so. I am thinking it will be a matter of using a global variable but if anyone could help I would appreciate it.

I have the following script called "highlight functions"...here is the code for that script...

var grids = new Array();
var buttPages = new Array();

initgrids();
nogrids();

function nogrids(){
for(var i=0;i

My Product Information:
Acrobat 3D 8.1.6, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Way too much code and not enough real information. And none of the code indents came through so it's mostly unreadable. Please use the BBCode "Code" tag to make it easier to look at.

Now heres the critcal information:
Where is this code located, i.e. the code where the data will be shared across? Is it in a document level script? a folder level script? A button Script? Same document? different documents? This is the real and only data you need to provide because the sharing mechanism depends entirely on the locations of the code.

Since it appears that data is being shared between two pieces of code within the same document context the best place to put the shared data is in a document level variable. There are two ways to create a document level variable.

1. Declare a variable in a document level script

2. Use the "this.varName" notation to attach the data to the document object.

One more thing. At the top of your code the two functions "initgrids()" and "nogrids()" are called before they are defined. These functions must be defined before they are called.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

subieguy2
Registered: Apr 30 2009
Posts: 15
The code is located in 1 document, at the document level, in 2 different script files. One script is called "highlight function" and the other script is called "callout function".

I am very new and have stumbled my way through the script I currently have. So I apologize for the extra junk and poor formatting.

Highlight functions script info....
My var grids = new Array(); is pulling any button in the document with the name "grids" in it.
It assigns it a value grids.length to newField.name and finds out what page number the named button resides on newField.page.

I want to pass those values into my callout functions script. This was my best thought pattern of how to pass the assigned value and what page it resides on. But again I am new to this and don't know how to pass the name, assigned value, and what page the button resides on into the other script.

onlygrid(grids.length, newField.page);

The callout functions script contains all of the button functions. In this instance callout1(); is executed when the user clicks on the button.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Sorry if I was a bit gruff. Long, difficult to read sections of code is one of my pet peeves.

If the variable "grids" is defined in a document level scirpt then it is visible to every script in the PDF. There is no reason to pass it into any function, unless you are using it in some indirect or special way.

The name of a field cannot be changed once the field has been created. At least it can't be changed from JavaScript. The "field.name" property is ReadOnly.

It looks like you are saving the button pages in the "buttPages" array and the field in the "grids" array. So as long as these two arrays are in sync, you have everything you need to call a function and pass in the name and page number of a field.

There are definately better ways to write the code, but I don't really get what it is you are trying to do so I don't know what to tell you about the implementation.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script