0

I'm working on a survey that requires setting the maximum range of a Qualtrics HSlider based on the response to a previous question. I've been able to pipe the result of that question to set the current value, but not the maximum.

I've looked at other stackoverflow questions that have not had solutions, so I figured I would ask the question again to see if anyone has solved this recently. The closest I've found is this response where I get the error: "Cannot set property 'maxValue' of undefined." Looking at other various documents it seems that the primary issue is that there is not a single slider class, but a collection of div tags that make up the slider.

Thanks for any help you might have!

Edit: Here's the code I've been trying to use, but I don't think it will work due to the lack of a distinct slider object.

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*/

});
  • 2
    Pretty hard to debug your problem without being able to see the code you're using. – CertainPerformance May 01 '18 at 04:30
  • I added the code to the original post. I don't think that it is headed the right direction at all because I don't think there is an actual slider object that can be found with the way Qualtrics now handles sliders. It appears that they are just a collection of HTML DIV tags and listeners. – user2993360 May 02 '18 at 14:54

0 Answers0