I am trying to implement a timer so that after a given time the user is automatically moved to the next block.
This questions is literally EXACTLY what I am trying to implement: https://www.qualtrics.com/community/discussion/comment/5616#Comment_5616
In that question, someone said I should create embedded data before my block with a value of 180.
Then, apparently, the following code should automatically move the user to the end of the block after 180 seconds.
var timeleft = parseInt("${e://Field/TimeLeft})");
var timer = setInterval(function () {
if (timeleft <= 0) {
clearInteval(timer);
$('NextButton').click();
}
timeleft--;
}, 1000);
$('NextButton').onclick = function (event) {
Qualtrics.SurveyEngine.setEmbeddedData('TimeLeft', timeleft);
}
However, whatever I try to do the, when I try to log the value of TimeLeft, nothing gets logged to the console.
I added an image how I am currently adding the embedded data before my block.
What am I doing wrong here?
Hi there,
Your code/process seemed to work out for me in terms of logging the time. The only difference is that I had to add the following code to my JS at the bottom:
Qualtrics.SurveyEngine.addOnUnload(function()
{
timer = clearInterval();
});
This is, of course, if "logged to the console" means logged as an embedded data field. Otherwise, be sure to add console.log(timeleft) in various places throughout your code above. For example, I tested with:
Qualtrics.SurveyEngine.addOnload(function()
{
var timeleft = parseInt("${e://Field/TimeLeft})");
console.log(timeleft);
var timer = setInterval(function () {
if (timeleft <= 0) {
clearInteval(timer);
$('NextButton').click();
}
timeleft--;
}, 1000);
$('NextButton').onclick = function (event) {
Qualtrics.SurveyEngine.setEmbeddedData('TimeLeft', timeleft);
console.log(timeleft);
}
});
In terms of moving to the end of the block, this code won't automatically do that. Are you trying to do this just for one questions, or over multiple questions?
Hi there,
Your code/process seemed to work out for me in terms of logging the time. The only difference is that I had to add the following code to my JS at the bottom:
Qualtrics.SurveyEngine.addOnUnload(function()
{
timer = clearInterval();
});
This is, of course, if "logged to the console" means logged as an embedded data field. Otherwise, be sure to add console.log(timeleft) in various places throughout your code above. For example, I tested with:
Qualtrics.SurveyEngine.addOnload(function()
{
var timeleft = parseInt("${e://Field/TimeLeft})");
console.log(timeleft);
var timer = setInterval(function () {
if (timeleft <= 0) {
clearInteval(timer);
$('NextButton').click();
}
timeleft--;
}, 1000);
$('NextButton').onclick = function (event) {
Qualtrics.SurveyEngine.setEmbeddedData('TimeLeft', timeleft);
console.log(timeleft);
}
});
In terms of moving to the end of the block, this code won't automatically do that. Are you trying to do this just for one questions, or over multiple questions?
I’m trying to have the yes/no response recorded in addition to the time. The time has been working fine but the yes/no responses were not being recorded. I have 60 questions that I need the data recorded. I know I will need to adjust the JS for each question and I suspect I will need to add an embed block before each one as well.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.