2

I have a PDF form and I'm trying to declare a global variable in the Document-level Javascript editor... I'm using

global.myVariable = "0";

and then on a field in the form, I'm running the code:

if(myVariable == "0"){

  app.alert("Hello!");

  myVariable = "1";

}

So that it only brings up the alert once. However, it's bringing it up every time I enter anything into any field, which is annoying. Please advise!

Veger
  • 37,240
  • 11
  • 105
  • 116
Lena
  • 21
  • 1
  • 2

2 Answers2

3

You can declare a global variable anywhere by doing:

myVariable = 1;

However it's safest if you declare your variable in the top-most scope:

var myVariable = 1;

The only issue you have to remember is to make sure you don't override myVariable anywhere else.

goatslacker
  • 10,032
  • 2
  • 15
  • 15
2

if you declare the variable as global.myVariable you will need to write your if-statement as:

if(global.myVariable === "0"){

    app.alert("Hello!");

    global.myVariable = "1";

}
John Kalberer
  • 5,690
  • 1
  • 23
  • 27