How To: Button used global variable or function


I have a variable counter (question) that I tried to make global. I have button (Button0) that I want to increment the counter and then call a function. I get a message that the “question” variable is not defined. I defined the counter and function both inside and outside of fd.spRendered but neither worked.

How can I have a button use a variable or call a function?

fd.spRendered(function() {
var question = 0;

function populateQuestion(qst) {
    //do something

fd.control("Button0").onclick = "question += 1; populateQuestion(question);";



Dear Marion,

You can define the variable in the window scope like this: “window.question”.