Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#NextButton").hide();
var x_val=0; // set this variable equal to 0. I know this doesnt work in later local functions. How to define it?
jQuery('#Button').on('click', () => {
var x_val=1; // set this variable equal to 1
});
// after ten seconds, hide timer, show MissServiceMessage
setTimeout(function(){
if (x_val==0){
jQuery("#NextButton").click();
}
}, 10000);
}, 30000);
});
Solved
How to set a global variable and use it in different functions?
Best answer by ChiragK
Try defining variable like this.
var x_val=0; //define it at the top
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#NextButton").hide();
jQuery('#Button').on('click', () => {
x_val=1; // don't use 'var x_val' as variable is already defined at the top.
});
// after ten seconds, hide timer, show MissServiceMessage
setTimeout(function(){
if (x_val==0){
jQuery("#NextButton").click();
}
}, 10000);
}, 30000);
});
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
