【问题标题】:In Qualtrics surveys, how can you use JavaScript to dynamically set the range of a slider?在 Qualtrics 调查中,如何使用 JavaScript 动态设置滑块的范围?
【发布时间】:2014-06-12 15:50:33
【问题描述】:

我在 Qualtrics 中进行了一项调查,需要让我的项目根据变量显示不同的滑块值,在我的例子中,是来自循环和合并的值。这似乎不是你可以用管道文本做的事情,所以我必须弄清楚如何在 Javascript 中做到这一点。

我只是发布这个作为提供我自己找到的答案的机会。与 Qualtrics 一样,您的里程可能会有所不同,这可能需要根据您的具体情况进行修改。特别是,问题 ID 和 postTags 会根据它是否处于循环/合并中以及可能取决于其他因素而变化。

【问题讨论】:

    标签: javascript qualtrics


    【解决方案1】:

    将以下代码放入问题的javascript部分:

    // 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)
        }
    }
    
    var currentQuestionInfo = this.getQuestionInfo()
    var currentQuestionID = currentQuestionInfo.QuestionID
    // Now call the function
    setSliderRange(currentQuestionInfo, theMaxValueYouWant)
    

    如果您觉得我的回答有帮助,请帮助提高我的声誉,将“qualtrics”添加为有效标签!或者,如果其他声誉超过 1500 的人愿意这样做,那将非常有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 2016-08-02
      相关资源
      最近更新 更多