Store and code values of range sliders as embedded data field in Qualtrics

时间:2018-06-04 16:51:37

标签: javascript slider qualtrics

I would like to store the values of several range sliders, code them as "0"/"1", add them up and store the sum in an embedded data field in Qualtrics. However, with my code below, it only codes and stores the value of the last moved slider. How can I circumvent that and store the values of all sliders?

Qualtrics.SurveyEngine.addOnload(function()
{
var sliders = document.getElementsByClassName('more-left');
var len     = sliders.length;

for ( var i = 0; i < len; i++ ) {
    var slider = sliders[i];

    slider.addEventListener('change', function() {
        updateValue(this);
    });

    updateValue(slider);
}

function updateValue(slider) {
    var id        = slider.id;

    if (!id) {
        return;
    }

    var val       = document.getElementById(id + '_value');


    if (val) {
        val.innerHTML = slider.value; 
    }
var question_text = slider.value
if (question_text == 50) {
 score = 1;
}
else {
    score = 0;
} 

    Qualtrics.SurveyEngine.setEmbeddedData("Output",score);}});

Thank you!

0 个答案:

没有答案