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!

2 Answers 2

3

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";

}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.