【问题标题】:Displaying count of radio buttons selected in Qualtrics显示在 Qualtrics 中选择的单选按钮的数量
【发布时间】:2018-06-15 16:12:32
【问题描述】:

我让 Qualtrics 调查的受访者选择将两种不同数量的资金分配给一组人员。因此,对于每个人,受访者必须选择给予 0 美元或 10 美元。

对于特定的外观和功能,我们决定使用“Scaled Response (Likert)”的并排问题,只有这两个选项和一个单一答案,因此我们只得到一个包含两个答案选项的列每一行,只能选择其中一个。此外,我们特别希望受访者给一半人 10 美元,给另一半人 0 美元,并通过自定义验证实现了这一点。因为有很多选项,我们只想在页面上实时显示有多少人获得了 10 美元,有多少人获得了 0 美元(即在两个答案的每一个中选择了多少单选按钮列)。

我看到很多人询问所选单选按钮的总数,但不确定对这些问题(涉及某种点击事件侦听器)给出的答案是否适用于并排问题,并且,至关重要的是,我不认为区分这两个组(即,如果它们并排工作,它们只会显示总共单击了多少单选按钮,而不是按组显示)。对于自定义验证,显然 Qualtrics 准确地保留了我想要的计数,因为“$10(计数)”等于 X,并且“$0(计数)”等于 X,其中 X 是总数的一半的人,但我不确定自己在一些 Javascript 中使用什么 sn-p 代码。

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

更新:我尝试过使用一些绝对不起作用的 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;
            }
        }
        }
    })
});

【问题讨论】:

    标签: javascript radio-button qualtrics


    【解决方案1】:

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

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 2011-02-07
      相关资源
      最近更新 更多