Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 显示Qualtrics中所选单选按钮的计数_Javascript_Radio Button_Qualtrics - Fatal编程技术网

Javascript 显示Qualtrics中所选单选按钮的计数

Javascript 显示Qualtrics中所选单选按钮的计数,javascript,radio-button,qualtrics,Javascript,Radio Button,Qualtrics,我让Qualtrics调查的受访者选择将两种不同金额的钱分配给一组人。因此,对于每个人,受访者必须选择0美元或10美元 对于特定的外观和功能,我们决定使用一个并排的问题和一个“缩放响应(Likert)”,其中只有这两个选项和一个答案,因此我们只得到一列,每行有两个答案选项,只能选择其中一个。此外,我们特别希望受访者给一半人10美元,给另一半人0美元,并通过定制验证实现了这一点。因为有相当多的选项,我们只想在页面上实时显示有多少人获得了10美元,有多少人获得了0美元(即在两个答案栏中分别选择了多少

我让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>
您已将$0分配给此数量的组:0
我的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;
            }
        }
        }
    })
});
Qualtrics.SurveyEngine.addOnReady(函数()
{
var total1=0;
var total2=0;
观察('mousemove',函数(事件,元素){
/*
SBS问题类型的元素ID(Element.ID)
QR~QID9#1~[行号(即社会团体)]~[答案栏号(即$100为1,$0为2)]
*/
如果(element.type=='radio')
{
sumCol1();
函数sumCol1(){

对于(var i=1;i如果有人好奇或需要类似的东西,我已经解决了这个问题,下面的内容对我很有用。希望将来对其他人有用

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');
        }
    }
}
Qualtrics.SurveyEngine.addOnReady(函数()
{
var total1=0;
var total2=0;
变量alloclarge=[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];
/*
SBS问题类型的元素ID(Element.ID)
QR~QID9#1~[行号(即社会团体)]~[答案栏号(即$100为1,$0为2)]
*/
this.questionclick=函数(事件、元素){
//对于单答案多项选择题,元素类型将为radio
如果(element.type=='radio')
{
var qType=this.getQuestionInfo().QuestionType;//获取问题类型代码(SBS=并列问题)
如果(qType=='SBS'){
//我们需要先将元素ID拆分为#
//var sbsElement=element.id.split(“#”)[1];
var matrxTQid=element.id.split(“#”)[0]。split(“~”)[1];//获取问题id
var matrx=element.id.split(“#”)[1];
var colNum=matrx.split(“~”)[0];//由于列是第一列,我们需要通过在#号处拆分将其与问题ID分开
}
var rowNum=element.id.split(“~”)[2];//获取行号
var eleNum=element.id.split(“~”)[3];//获取元素号
对于(变量i=1;i<21;i++){
if(eleNum==1&&rowNum==i&&allocclarge[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&&allocclarge[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如果(eleNum==1&&rowNum==i&&allocclarge[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如果(eleNum==2&&rowNum==i&&allocclarge[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;
}否则{
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;
}   
}
函数groupSum(){
如果(总数1>10){
警报(“您已向10多个组分配了100美元”);
}
否则如果
<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>