Request custom code | Experience Community
Skip to main content
Question

Request custom code

  • June 25, 2026
  • 1 reply
  • 0 views

Hi everyone, for a survey in qualtrics I want to link the answer of one question to the next question. The first question is QID16, this is an drag and drop question in which six attributes are rated from least to most important. In the next question which is QID17 these same six attributes are used in a slider question, in which all six attributes have to be scored 0-100. However I would like the attributed rated as most important in QID16 to automatically be scored a 100 in the next questions (so it will be dependent on the answer in the previous question). 

Could someone help me with the javascript coding for this question? I am very inexperienced with coding, and the chat and other AI so far have not helped me at all.

Thanks in advance!

1 reply

nikamshubham73
Level 2 ●●
Forum|alt.badge.img+4

Hi ​@hildesluijter,

Thanks for mentioning the QID. You can try the below HTML and JS on your Slider Question. Whichever attribute the respondents keeps at the Top will be set to 100 in the Slider Question. This code will not work, if the New Survey Taking Experience is Enabled. Hope this helps.

In Drag and Drop Question, assign the span class to each attribute, see example below:
<span class="A">Choice 1</span>
<span class="B">Choice 2</span>
<span class="C">Choice 3</span>
<span class="D">Choice 4</span>
<span class="E">Choice 5</span>
<span class="F">Choice 6</span>

In the Slider question’s Question Text, paste the below codes

HTML Code:

<div id="hidden-top-choice" style="display: none;">${q://QID16/ChoiceGroup/ChoiceWithLowestValue}</div>

<!-- The above is for the Attribute present at the Top, if you want the last Attribute, replace “Lowest” with “Highest” -->   

JS Code:

Qualtrics.SurveyEngine.addOnReady(function() {
    // 1. Read the HTML safely from the hidden div we created
    var hiddenDiv = document.getElementById('hidden-top-choice');
    
    // Make sure the div exists and has content
    if (hiddenDiv) {
        // 2. Find the span inside that hidden div
        var spanElement = hiddenDiv.querySelector('span');
        
        if (spanElement) {
            var className = spanElement.className; // Gets "A", "B", "C", etc.
            
            // 3. Map your Span Classes to the Slider's Choice IDs
            var classToChoiceMap = {
                "A": 1, 
                "B": 2, 
                "C": 3, 
                "D": 4, 
                "E": 5, 
                "F": 6  
            };
            
            var targetChoiceId = classToChoiceMap[className];
            
            // 4. Set the slider to 100
            if (targetChoiceId !== undefined) {
                this.setChoiceValue(targetChoiceId, 100);
            }
        }
    }
});