显示在Qualtrics

时间:2018-06-15 16:12:33

标签: javascript radio-button qualtrics

我对Qualtrics调查的受访者选择将两种不同的金额分配给人员列表。因此,对于每个人,被访者必须选择提供0美元或10美元。

对于特定的外观和功能,我们决定使用"缩放响应(Likert)"只有这两个选项和一个单一答案,所以我们只得到一列,每行有两个答案选项,只能选择其中一个。此外,我们特别希望受访者能够为一半人提供10美元,为另一半人提供0美元,并且通过自定义验证实现了这一目标。因为有相当多的选项,我们只想在页面上实时显示有多少人获得10美元,有多少人获得0美元(即每个人中选择了多少个单选按钮)两个答案栏)。

我看到很多人询问所选的单选按钮总数,但不确定这些问题的答案(涉及某种点击事件监听器)是否适用于并排问题而且,关键的是,我不认为区分这两个群体(即如果他们并排工作,他们只会显示总共点击了多少个单选按钮,而不是按群组点击)。对于自定义验证,显然Qualtrics保留了我想要的计数,因为我已经将它作为" $ 10(计数)"等于X," $ 0(计数)"等于X,其中X是总人数的一半,但我不确定在一些Javascript中我自己使用哪些代码片段。

有关如何计算并排问题的任意一列中所选单选按钮数量的任何建议或想法?谢谢!

更新:我已经尝试过使用一些肯定无效的Javascript。我试图在并排问题上浏览每一栏,并在计数器中发现其中一个单选按钮已被选中时添加+1(我尝试了两个不同的下面的代码中的方法,看看是否有效)。然后我在问题文本的HMTL中有以下内容:

You have allocated $0 to this number of groups: <span id="total2">0</span></span>

我的Javascript:

Qualtrics.SurveyEngine.addOnReady(function()
{
    var total1 = 0;
    var total2 = 0;

document.observe( 'mousemove', function(event,element){
/*
Element ID (element.id) for SBS question type
QR~QID9#1~[row number (i.e. social group)]~[answer column number (i.e. $100 is 1, $0 is 2)]
*/

    if (element.type == 'radio')
    {
        sumCol1();

        function sumCol1() {
            for(var i = 1; i <= 20; i++) {
                if (jQuery("input[name="+'QR\~QID9\#1'+'\~'+i+'\~'+'1'+"]").is(":checked")) total1 = total1 + 1;
                else total1=total1;
            }
        }

        sumCol2();

        function sumCol2() {
            for(var i = 1; i <= 20; i++) {
                if ($("input[name="+'QR\~QID9\#1'+'\~'+i+'\~'+'2'+"]:checked")) total2 = total2 + 1;
                else total2=total2;
            }
        }
        }
    })
});

1 个答案:

答案 0 :(得分:0)

如果有人好奇或需要类似的东西,我已经解决了这个问题,以下内容对我有用。希望将来对其他人有用!

Qualtrics.SurveyEngine.addOnReady(function()
{
var total1 = 0;
var total2 = 0;

var alloclarge=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var allocsmall=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

/*
Element ID (element.id) for SBS question type
QR~QID9#1~[row number (i.e. social group)]~[answer column number (i.e. $100 is 1, $0 is 2)]
*/

this.questionclick = function(event,element){
//for a single answer multiple choice question, the element type will be radio
if (element.type == 'radio')
{
  var qType = this.getQuestionInfo().QuestionType;    // get the question type code (SBS=side by side question)
        if (qType=='SBS') {
            // we need to split the element ID first by #
            // var sbsElement = element.id.split('#')[1];
            var matrxTQid = element.id.split('#')[0].split('~')[1]; // get question ID
            var matrx = element.id.split('#')[1];
            var colNum = matrx.split('~')[0]; // since column is first we need to separate it from the question ID by splitting at the # sign
        }
        var rowNum = element.id.split('~')[2];  // get row number
        var eleNum = element.id.split('~')[3]; // get element number        

    for(var i = 1; i < 21; i++) {
        if (eleNum==1 && rowNum==i && alloclarge[i-1]==0 && allocsmall[i-1]==0) {
            total1=total1+1;
            alloclarge[i-1]=1;
            groupSum();
            document.getElementById("total1").innerHTML=total1;
            document.getElementById("total2").innerHTML=total2;             
        } else if (eleNum==2 && rowNum==i && alloclarge[i-1]==0 && allocsmall[i-1]==0) {
            total2=total2+1;
            allocsmall[i-1]=1;
            groupSum();
            document.getElementById("total1").innerHTML=total1;
            document.getElementById("total2").innerHTML=total2; 
        } else if (eleNum==1 && rowNum==i && alloclarge[i-1]==0 && allocsmall[i-1]==1) {                            
            total1=total1+1;                
            total2=total2-1;
            alloclarge[i-1]=1;              
            allocsmall[i-1]=0;
            groupSum();
            document.getElementById("total1").innerHTML=total1;
            document.getElementById("total2").innerHTML=total2; 
        } else if (eleNum==2 && rowNum==i && alloclarge[i-1]==1 && allocsmall[i-1]==0) {                            
            total1=total1-1;                
            total2=total2+1;
            alloclarge[i-1]=0;              
            allocsmall[i-1]=1;
            groupSum();
            document.getElementById("total1").innerHTML=total1;
            document.getElementById("total2").innerHTML=total2; 
        } else {
            total1=total1;
            total2=total2;
            alloclarge[i-1]=alloclarge[i-1];                
            allocsmall[i-1]=allocsmall[i-1];
            document.getElementById("total1").innerHTML=total1;
            document.getElementById("total2").innerHTML=total2; 
        }   
    }

    function groupSum() {
        if (total1 > 10) {
            alert('You have allocated $100 to more than 10 groups');
        }
        else if (total2 > 10) {
            alert('You have allocated $0 to more than 10 groups');
        }
    }
}

}});

在我的问题的HTML中有以下内容:

<div><br />
<span style="color:#000000;"><span style="font-size:16px;"><span style="font-family:arial,helvetica,sans-serif;">You have allocated $100 to this number of groups: 
<strong><span id="total1" style="color:#E73F61;">0</span></span></span></span> </strong></div>
<span style="color:#000000;">You have allocated $0 to this number of groups: <strong><span id="total2" style="color:#E73F61;">0</span></span></strong>
相关问题