How to compare rank of objects from previous ranking task | XM Community
Skip to main content
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
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
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
I see, I tried again and it worked! Thanks a million 🙂

Leave a Reply