Copy link to clipboard
Copied
I'm trying to create an array that I can use for multiple validation scripts. I have a long list of fields that are set to "readonly = true". I have successfully created an array and loaded all of the fields needed.
var AdminFields = new Array(38);
AdminFields[0] ="formField1";
AdminFields[1] ="formField2";
etc.....
My problem is that I can only get the array to work locally. If I try to reference the array from another button I get a "ReferenceError: AdminFields is not defined". The only way to get the button to work is to list the entire array again in the script for that button.
I tried loading a document level function to create the array. I called the function "initAdminFields()". I thought this would allow me to reference "initAdminFields()" at the top of my script so I wouldn't have to recreate the array again. Didn't work.
Q: Is there a way to create a global array that can be used throughout a form?
Q: Where do you create a global array?
Q: How do you call the array in a script (like one for a button mouse up event)?
Thank you in advance. I am a casual javascript user. I appreciate everyone's patience as I grow my knowledge.
Hi what does "create a global array" mean? Try creating a variable outside of the function.
function foo(){
// local
var a = 'a'
//global
b = 'b'
}
// global
var c = 'c'
// global
d = 'd'
Copy link to clipboard
Copied
Hi what does "create a global array" mean? Try creating a variable outside of the function.
function foo(){
// local
var a = 'a'
//global
b = 'b'
}
// global
var c = 'c'
// global
d = 'd'
Copy link to clipboard
Copied
Thank you for the reply.
By "global array" I mean an array that I can load when the form loads. One that is persistent as long as the form is open and can be referenced in scripts later in the form.
I will try your example.
Copy link to clipboard
Copied
I made corrections to my code to remove "var" from the line statement. It worked.
Thank you for the quick rely.
Copy link to clipboard
Copied
Use a target engine. At the top of a script add this line:
#targetengine anystringwilldo;
var AdminFields = new Array(38);
AdminFields[0] ="formField1";
AdminFields[1] ="formField2";
This creates a so-called persistent variable, one that persists after the script finishes but in this engine only. Now any other script that uses the same engine has access to the variable (as Sychev demonstrated in another thread only yesterday:))