Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

How to compare rank of objects from previous ranking task

Maria_Mich
Maria_Mich NetherlandsCommunity Member - Trial User Qubie ✭

Hello, for my study I have the respondents rank (drag and drop) 9 soft drinks according to their preferences. Peach IT and Lemon IT are two of the previously ranked items, and in the next question I want to display the one that got the higher ranking among those two. How can I do this using Javascript? Thanks

Tagged:

Best Answer

  • [Deleted User]
    [Deleted User] Qubie ✭
    Accepted Answer

    Hello @Maria_Mich ,

    Following solution will work for Rank order(Drag and Drop) question type

    Suppose your Peach IT and Lemon IT are first and second choice while designing your question type as shown below:

    Step 1: Create an embedded data(HigherRank) in the survey flow before Rank order(Drag and Drop) question

    Step 2: Paste the following code in the js(onReady) of Rank order(Drag and Drop) question

    var that=this.questionId;
        $(document).on('DOMSubtreeModified', function(){
        if(parseInt(jQuery("[id='QR~"+that+"~1'] span.rank").text()) > parseInt( jQuery("[id='QR~"+that+"~2'] span.rank").text())){
        Qualtrics.SurveyEngine.setEmbeddedData( 'HigherRank', jQuery("#"+that+"-2-label span").text() );
        }else{
        Qualtrics.SurveyEngine.setEmbeddedData( 'HigherRank', jQuery("#"+that+"-1-label span").text() );    
        }
        });
    

    Step 3: The above code will set the embedded data(HigherRank) with choice with higher rank, and now in the next question you can pipe in the embedded data(HigherRank)

    Note: If your option is not in the above(image) sequence, then you need to modify '~1', '-1' and '~2', '-2' in the above code based on your options position

Answers

  • Maria_Mich
    Maria_Mich NetherlandsCommunity Member - Trial User Qubie ✭

    Hi and many thanks for your answer!
    In my case the order that the options are displayed for each participant have to be randomized, so I don't have a fixed position for Lemon and Peach to use in this code.
    What would you recommend in this case?

  • @Maria_Mich said:
    Hi and many thanks for your answer!
    In my case the order that the options are displayed for each participant have to be randomized, so I don't have a fixed position for Lemon and Peach to use in this code.
    What would you recommend in this case?

    By randomized, you mean you have applied randomization on options, right?
    With randomization, Still the code will work. If possible just provide the screenshot of the options here

  • Maria_Mich
    Maria_Mich NetherlandsCommunity Member - Trial User Qubie ✭

    I see, I tried again and it worked! Thanks a million :)