Solved
How to compare rank of objects from previous ranking task
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
Best answer by Anonymous
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
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 positionEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.
