在 Qualtrics 中实现多页计时器 [英] Implementing a multi-page timer in Qualtrics

查看:62
本文介绍了在 Qualtrics 中实现多页计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在进行的一个研究项目,我正在尝试使用 Qualtrics 上的 Javascript 功能实现一个计时器,该功能将跟踪时间并将其显示给多个页面的主题.

For a research project I'm working on I'm trying to implement a timer using the Javascript functionality on Qualtrics that will keep track of time and display it to subjects over multiple pages.

我的代码的总体思路是跟踪多个页面的定时倒计时.也就是说,我有一系列任务,每个任务都在一个单独的页面上,但在同一个块中,我想显示每次加载新页面时还剩多少时间.

The general idea of my code is to keep track of a timed countdown over multiple pages. That is to say, I have a series of tasks, each on an individual page but in the same block, and I'd like to display how much time is left every time a new page loads.

要做到这一点,首先我定义了几个嵌入的数据字段timeleftrounded"和start time",然后将值留给以后分配.

To do this, first I've defined several embedded data fields "timeleftrounded" and "start time" and left the values to be assigned later.

其次,我将以下代码直接放在我希望计时器启动的页面之前的最后一个问题上.我的目的是让这段代码读取当前时间来定义嵌入数据start_time"

Second, I put the following code on the last question directly before the pages I want the timer to start on. My intention is for this code to read in the current time to define the embedded data "start_time"

    Qualtrics.SurveyEngine.addOnload(function()
{
Event.observe($('NextButton'), 'click', function (e) 
    {    
        Qualtrics.SurveyEngine.setEmbeddedData("start_time", Date.now());
     });
});

在下一页我的任务开始,因为我希望科目总共有 40 分钟,所以我只写了40 分钟",不需要代码.但是在那个问题上,我有更多的代码可以计算单击加载下一页的按钮时剩余的时间(以分钟为单位).

On the next page my tasks begin, and as I want subjects to have 40 minutes total, I just have "40 minutes" written in, no code necessary. But on that question I have more code that should then calculate the amount of time remaining (in minutes) when the button to load the next page is clicked.

    Qualtrics.SurveyEngine.addOnload(function()
{
    Event.observe($('NextButton'), 'click', function () 
{ 
        var timeleftrounded = (2400000- (Date.now() - Number("${e://Field/start_time}")))/60000;    
    Qualtrics.SurveyEngine.setEmbeddedData("timeleftrounded",timeleftrounded);  
        });
    });

下一页用下面的代码把这个变量timeleftrounded"四舍五入到第一个小数点显示给题主,

The next page uses the following code to round this variable "timeleftrounded" to the first decimal point and display it to the subject,

$e{ round(e://Field/timeleftrounded , 1) }

这就是我的困惑开始的地方:虽然当我使用查看块..."功能时这段代码可以正常工作,但当我使用完整的调查预览模式或启动调查(我制作了一份副本)时,计时器却没有不行——除非我对一个问题给出了错误的答案,否则它只会显示0".每个页面都有一个带有验证检查的问题,一旦我至少给出了一次错误的答案,计时器就会再次工作,但是如果我只给出正确的答案,则计时器永远不会工作.

Here's where my confusion begins: although this code works properly when I use the "View Block..." function, when I use the full survey preview mode, or launch the survey (I made a copy), the timer doesn't work--unless I give a wrong answer to a question, it will just display "0". Each page has a question with a validation check, and once I give a wrong answer at least once, the timer works again, but if I only give correct answers, the timer never works.

希望我遗漏了一些明显的东西,但我无法在网上的任何地方找到解决方案,所以我认为这可能是其他人也会感兴趣的.

Hopefully I'm missing something obvious, but I wasn't able to find the solution anywhere online so I figured this might be something other people would have an interest in as well.

推荐答案

在 Next Button 上添加事件侦听器通常不起作用,因为 Qualtrics 在 Next Button 上有自己的事件侦听器.

Adding an event listener on the Next Button usually doesn't work because Qualtrics has its own event listener on the Next Button.

我将建议一种更简单的方法.使用内置的嵌入变量 Q_TotalDuration,它总是以秒为单位显示当前调查的总持续时间.

I'm going to suggest a much simpler approach. Use the built-in embedded variable Q_TotalDuration which always has the current total duration of the survey in seconds.

在调查流程中,就在您的定时问题开始之前:

In the survey flow, just before your timed questions start:

start_time = ${e://Field/Q_TotalDuration}

标题中的 HTML:

<div id="timeLeft" style="text-align:right"></div>

关于定时问题的 JavaScript(每页只需要一个):

JavaScript on your timed questions (just need one on each page):

Qualtrics.SurveyEngine.addOnload(function()
{
    var timeleftrounded = (2400 - (parseInt("${e://Field/Q_TotalDuration}") - parseInt("${e://Field/start_time}")))/60;
    timeleftrounded = timeleftrounded.toFixed(1);  
    $('timeLeft').update(timeleftrounded + " minutes left");
});

这篇关于在 Qualtrics 中实现多页计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆