Solved
Javascript: Instead of automatically clicking next, how to code it to go to a certain question?
Dear friends,
My friend wrote me some really nice code! I asked him to write some javascript code to create a timed test. They start a block of a 100 questions, but when it starts it starts a countdown. When the countdown reaches 0 the script automatically skips to the next question. This happens for all the questions that see that the timer stands at zero. However, with a 100 questions it goes through all the questions so quickly, it looks like it survey is crashing.
Is there a way to adjust this code to skip to a certain question instead if the timer reaches 0? Currently, it reads the script and goes to the next question in line, which then does the same. Is there a way to instead instruct Qualtrics to skip everything and go to my "Post-measure" question?
Qualtrics.SurveyEngine.addOnload(function()
{
function startTimer(duration, display) {
if (--timer < 0) {
clearInterval(myTimer);
timeOver();
}
}
var timerSeconds = parseInt("${e://Field/timeRemaining}");
display = document.querySelector('#time');
if (timerSeconds > 0) {
startTimer(timerSeconds, display);
}
var timeOver = function () {
document.getElementById("timer_1").innerHTML = "Time is up.";
$('NextButton').click();
x = 1;
var bgColor = setInterval(change, 1000);
}
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Voer uw JavaScript hier uit wanneer de pagina volledig wordt weergegeven*/
var timerSeconds = parseInt("${e://Field/timeRemaining}");
if (timerSeconds === 0) {
$('NextButton').click();
}
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Voer uw JavaScript hier uit wanneer de pagina nog niet geladen is*/
});
Best answer by TomG
> @Yuri said:
> Thanks a lot Tom!
>
> When I test run it, it does seem to automatically initiate "click next button" command after time runs out. The time remaining is instead set in survey flow. I think that is how it works?
>
> So you would change the last part like this? Sorry, I'm really new to coding! (this is something I found on the web)
>
> var timerSeconds = parseInt("${e://Field/timeRemaining}");
> Display Logic: Show only if timeRemaining > 0];
> }
You add display logic to the Qualtrics questions, not the JavaScript. Once that is done, you can remove the addOnReady function from the script.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
