向 qualtrics 问题添加按钮,该按钮(随机)将文本附加到问题

Add button to qualtrics question which (randomly) appends text to question

我有一项 Qualtrics 调查,我向人们展示了一场赌博,并要求他们决定是否参与。在此之前,我希望他们虚拟地进行 20 次赌博并查看每次的结果。看起来最简单的方法是在问题文本中添加一个按钮,按下该按钮时,会随机附加一个新的赌博结果——要么赢要么输。例如。如果我让他们玩一场有 90% 获胜机会的赌博,90% 的时间他们按下按钮,他们应该看到页面上附加一个新的“WIN”,而 10% 的时间他们应该看到“LOSE” " 附加到页面。

但是,我正在努力让这一切在 qualtrics 中发挥作用。在dividually 中,我知道我需要做什么,我想 -- 如果我在问题 HTML 本身中做一个 div,然后做一个按钮它将使用 JQuery 中的 .append 函数来添加输赢消息(即 .append(<p> WIN! </p>) 或类似的消息),它应该给我我的基本功能。但是,当涉及到实际实施时,我完全迷失了,并弄清楚问题本身的 html 与 Qualtrics 的 JavaScript 部分应该包含什么。

理想情况下,我也希望要求他们执行此操作 20 次,但我无法跟踪如何跟踪。任何帮助(或关于更好的方法的建议)将不胜感激。我真的很想避免在 Qualtrics 中使用调查流程,因为对于这么多的试验来说这看起来非常混乱,但如果有一个好的方法来做到这一点,我也会很感激那里的建议。

编辑:我有一个实现,这不是我真正想要的,但在根本不使用 JQuery 的情况下也能获得类似的效果。

这不是解决此问题的 JQuery 或基于按钮的方法 -- 我无法弄明白。相反,我创建了一个循环和合并块,它由两个文本显示组成,中间有一个分页符。第一个文本显示会告诉他们按下按钮来模拟赌博。 Javascript本页会根据嵌入数据模拟赌博结果,然后更新另一个嵌入数据字段用于显示赌博结果,将显示在以下块中。

初始文本问题的 Javascript 看起来像这样,其中 q1start 是一个嵌入的数据字段,它设置了赌博获胜的概率:

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
    
    //turn starting probability into a variable
    var start_prob = parseInt("${e://Field/q1start}")
    console.log("next thing is start prob")
    console.log(start_prob)
    
    //draw a number 0-100 to see if we won the lottery
    var random_draw_result = Math.floor(Math.random()*100+1)
    //compare it to chances, set embedded data which will display outcome
    var outcome_display = (start_prob >= random_draw_result) ? "WIN!" : "LOSE!"
    console.log("draw")
    console.log(random_draw_result)
    console.log("outcome")
    console.log(outcome_display)
    Qualtrics.SurveyEngine.setEmbeddedData("outcome_display", outcome_display)

});

第二个文本问题看起来像:

“您的结果是 ${e://Field/outcome_display}”,其中嵌入的数据是上述 Javascript 的结果,这是在第一步中完成的。

然后我只是循环并合并了一堆,并设置它以便在最终循环之前的所有循环和合并中出现这两个文本问题。对于最后一个循环,我希望他们回答的实际问题出现了。

这是示例块的样子(在这种情况下,我只是让它进行了两个示例试验,然后是最终的实际试验):

调查流程如下所示:

原则上,如果我想一次显示所有赌博的结果,我想我可以通过为我将要做的每个循环创建一个结果显示嵌入式数据变量,然后让第二个问题每次只显示所有这些结果显示变量。

最后很简单,终于想通了。

用这个作为 HTML:

用单个问题做一个块
<p>Imagine you are considering a ${lm://Field/1}% gamble. Please simulate this gamble 20 times by pressing the button below</p>
<button id="gamble_btn">Simulate Gamble</button>

<p>&nbsp;</p>

<div id="results">&nbsp;</div>

对于这个块,使其成为一个循环并与单个字段合并,该字段是赢得每场赌博的概率。 然后,将以下 Javascript 添加到该问题:

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
    
    // Hide the continue button
    $('NextButton').hide();
    
    //Probability of winning the gamble
    var start_prob = parseInt("${lm://Field/1}") // Set this to the value for the loop and merge field
    
    var click_ct = 0 //initial # of trials should be 0
    var max_clicks = 20 //number of trials we want them to do
    var complete_alert = "You have finished all gambles" //alert msg for when they click post finishing all gambles
    var completion_message = "<p>You have finished all gambles! Press continue to move on. </p>" // msg to append when finished
    
    // This button allows you to simulate a gamble
    jQuery( "#gamble_btn" ).click(function() {
        console.log("press")
        // Calculate results of gamble, set display message
        var random_draw_result = Math.floor(Math.random()*100+1)
        var outcome_display = (start_prob >= random_draw_result) ? "<p style='color:green;'> WIN! </p>" : "<p style='color:red;'> LOSE! </p>"
        // If they've done less than 20 gambles, append the outcome
        if (click_ct < max_clicks){ // what to do on trials before the last one
            jQuery("#results").append(outcome_display) //display outcome of the trial
            click_ct++
        } else if (click_ct == max_clicks) { //what to do on last trial
            jQuery("#results").append(outcome_display) //append results of final trial
            jQuery("#results").append(completion_message) //append completion message
            $('NextButton').show(); //show the continue button
            jQuery(this).attr('disabled', true); //disable button presses
            click_ct++
        } else {
            alert(complete_alert)
        }
        console.log(click_ct)
    });

});