Qualtrics:在加载时动态设置滑块最大值

时间:2018-05-01 04:29:18

标签: javascript jquery slider qualtrics

我正在进行一项调查,该调查需要根据对上一个问题的回答来设置Qualtrics HSlider的最大范围。我已经能够管道该问题的结果来设置当前值,但不是最大值。

我查看了其他stackoverflow问题 那些没有解决方案,所以我想我会再问这个问题,看看最近是否有人解决了这个问题。我发现的最接近的是this response我得到错误:“无法设置未定义的属性'maxValue'。”看看其他各种文档,似乎主要问题是没有一个滑块类,而是构成滑块的div标签集合。

感谢您的帮助!

编辑:这是我一直试图使用的代码,但由于缺少一个独特的滑块对象,我认为它不会起作用。

Qualtrics.SurveyEngine.addOnload(function()
{
    // Set the slider range
    // First define the function to do it
    setSliderRange = function (theQuestionInfo, maxValue) {
        var postTag = theQuestionInfo.postTag
        var QID=theQuestionInfo.QuestionID
        // QID should be like "QID421"
        // but postTag might be something like "5_QID421" sometimes
        // or, it might not exist, so play around a bit.
        var sliderName='CS_' + postTag
        window[sliderName].maxValue=maxValue
        // now do the ticks. first get the number of ticks by counting the table that contains them
        var numTicks = document.getElementsByClassName('LabelDescriptionsContainer')[0].colSpan
            // do the ticks one at a time
            for (var i=1; i<=numTicks; i++) {
            var tickHeader='header~' + QID + '~G' + i
            // the first item of the table contains the minimum value, and also the first tick.
            // so we do some tricks to separate them out in that case.
            var tickSpanArray = $(tickHeader).down("span.TickContainer").children
            var tickSpanArrayLength=tickSpanArray.length
            var lastTickIndex=tickSpanArrayLength - 1
            var currentTickValue = tickSpanArray[lastTickIndex].innerHTML
            currentTickValue=currentTickValue.replace(/^\s+|\s+$/g,'')
            console.log('Tick value ' + i + ' is ' + currentTickValue)
            // now get the new value for the tick
            console.log('maxValue: ' + maxValue + ' numTicks: ' + numTicks + ' i: ' + i)
            var newTickValue = maxValue * i / numTicks //the total number of ticks
            tickSpanArray[lastTickIndex].innerHTML=newTickValue.toString()
            console.log('Changed tick value to ' + newTickValue)
        }
    }
    console.log(this.getQuestionInfo());
    var currentQuestionInfo = this.getQuestionInfo();
    var currentQuestionID = currentQuestionInfo.QuestionID;
    var Q8Response = parseInt("${q://QID8/ChoiceTextEntryValue}");
    // Now call the function
    setSliderRange(currentQuestionInfo, Q8Response)

});

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

});

0 个答案:

没有答案