Qualtrics Sum Matrix Table

时间:2015-07-09 13:15:53

标签: javascript qualtrics

我试图从这张图片中重新创建Qualtrics中的矩阵:

我发现的Javascript使用文字条目但我认为 个人资料多个答案 会更适合这个问题。我需要一种方法来允许用户选择多个项目并显示他们当前的总数。衷心感谢能够指引我朝着正确方向前进的人。



Qualtrics.SurveyEngine.addOnload(function() {
    var qid = this.questionId;
    $(qid).select('td.c4').last().down().hide();
    $(qid).select('td.c5').last().down().hide();
    var totalInput = $(qid).select('td.c6').last().down();
    totalInput.setAttribute("readonly", "readonly");
    totalInput.style.fontWeight = "bold";
    var c6 = $(qid).select('td.c6');
    for(var i=0; i < (c6.length - 1); i++) {
        c6[i].down().observe("keyup", function(event) {
            sumCol();
        }); 
    }   
    sumCol();   

    function sumCol() {
        var total = 0;
        for(var i=0; i < (c6.length - 1); i++) {
            var inputValue = parseInt(c6[i].down().value);
            if(isNaN(inputValue)) inputValue = 0;
            c6[i].down().value = inputValue;
            total = total + inputValue;
        }
        totalInput.value = total;
        if(total == 100) totalInput.style.color = "";
        else totalInput.style.color = "red";
    }   
});
&#13;
&#13;
&#13;

0 个答案:

没有答案