Can you reset / undo the ranking of a ranking question | Experience Community
Skip to main content
Solved

Can you reset / undo the ranking of a ranking question

  • February 4, 2026
  • 3 replies
  • 21 views

Forum|alt.badge.img+11

Hi All,

 

I have a ranking question (in classic theme, ie not the new simple theme), using choices from a previous question but hopefully that doesn’t matter..  I would like to know if it’s possible to undo / unset the ranking in case someone accidentally touches / drags one of the items but actually didn’t want to answer the question.

 

If there a way of doing this in code?

 

I’ve played around a bit getting a button setup but I’m not sure what the next steps would be.

 

Thanks

 

Rod Pestell  

Best answer by vgayraud

Hi,

Add a click listener to your button and use the setChoiceValue method to reset them to “”. You would also need to reset the ul element to clear the ranks visually.

Something like this should work in classic layout:

Qualtrics.SurveyEngine.addOnReady(function () {

var thisQuestion = this;
var qContainer = thisQuestion.getQuestionContainer();

var resetBtn = document.createElement("button");
resetBtn.type = "button";
resetBtn.textContent = "Reset Rankings";
resetBtn.style.marginTop = "10px";
resetBtn.style.padding = "5px 10px";
resetBtn.style.cursor = "pointer";
qContainer.appendChild(resetBtn);

resetBtn.addEventListener("click", function () {
var choices = thisQuestion.getChoices();
choices.forEach(function (choiceId) {
thisQuestion.setChoiceValue(choiceId, "");
});
var roList = qContainer.querySelector("ul[id$='~RO']");
if (roList) {
roList.classList.remove("Edited");
if (!roList.classList.contains("NotEdited")) {
roList.classList.add("NotEdited");
}
}
});

});

 

3 replies

vgayraud
QPN Level 7 ●●●●●●●
Forum|alt.badge.img+61
  • QPN Level 7 ●●●●●●●
  • Answer
  • February 4, 2026

Hi,

Add a click listener to your button and use the setChoiceValue method to reset them to “”. You would also need to reset the ul element to clear the ranks visually.

Something like this should work in classic layout:

Qualtrics.SurveyEngine.addOnReady(function () {

var thisQuestion = this;
var qContainer = thisQuestion.getQuestionContainer();

var resetBtn = document.createElement("button");
resetBtn.type = "button";
resetBtn.textContent = "Reset Rankings";
resetBtn.style.marginTop = "10px";
resetBtn.style.padding = "5px 10px";
resetBtn.style.cursor = "pointer";
qContainer.appendChild(resetBtn);

resetBtn.addEventListener("click", function () {
var choices = thisQuestion.getChoices();
choices.forEach(function (choiceId) {
thisQuestion.setChoiceValue(choiceId, "");
});
var roList = qContainer.querySelector("ul[id$='~RO']");
if (roList) {
roList.classList.remove("Edited");
if (!roList.classList.contains("NotEdited")) {
roList.classList.add("NotEdited");
}
}
});

});

 


Forum|alt.badge.img+11
  • Author
  • Level 4 ●●●●
  • February 4, 2026

Thanks ​@vgayraud that worked a treat!

 

Thanks very much

 

Rod


Forum|alt.badge.img+11
  • Author
  • Level 4 ●●●●
  • February 5, 2026

Hi all,

 

Thanks again to Vincent for the work around of resetting the Rank order question.  I have used this code now to provide an undo / reset button for the ranking question but then also add in some extra code i used to use but now enhanced to cope with the undo method.

 

The extra code (see below) will report the ranked data in a different way than Qualtrics does, making it much easier to understand what the most common top ranked items are.  It reports the choices ranked as number 1 in a rankx embedded field where x is 1 (meaning top) thru to whatever number of choices you are displaying.  There is then a field giving the full list in order of rank.  You must create the embedded fields in the survey flow beforehand.

 

Hope this helps someone

 

Thanks

 

Rod Pestell

 

UNDO / RESET button code

Qualtrics.SurveyEngine.addOnReady(function(){

// === code creates a undo button
var thisQuestion = this;
var qContainer = thisQuestion.getQuestionContainer();
var resetBtn = document.createElement("button");
resetBtn.type = "button";
resetBtn.textContent = "Undo";
resetBtn.style.marginTop = "10px";
resetBtn.style.padding = "5px 10px";
resetBtn.style.cursor = "pointer";
resetBtn.style.display = "block";
resetBtn.style.borderRadius = "5px";
resetBtn.style.marginLeft = "auto";
resetBtn.style.marginRight = "auto";

qContainer.appendChild(resetBtn);
resetBtn.addEventListener("click", function () {
var choices = thisQuestion.getChoices();
choices.forEach(function (choiceId) {
thisQuestion.setChoiceValue(choiceId, "");
});
var roList = qContainer.querySelector("ul[id$='~RO']");
if (roList) {
roList.classList.remove("Edited");
if (!roList.classList.contains("NotEdited")) {
roList.classList.add("NotEdited");
}
}
});

// === end of code


});

 

RECORD RANKING in embedded fields code

Qualtrics.SurveyEngine.addOnPageSubmit(function () {

// === code used to create a final ranked list of the choices in the ranking question
// === this handles the undo button feature via check the NotEdited status of the roList
var q = this;
var container = q.getQuestionContainer();
var roList = container.querySelector("ul[id$='~RO']");

var rankedLabels = [];

// Clear previous embedded data
if (roList) {
var max = roList.querySelectorAll("li").length;
for (var i = 1; i <= max; i++) {
Qualtrics.SurveyEngine.setEmbeddedData(
"Q14_rank" + i,
""
);
}
}

// If not ranked or reset, exit cleanly
if (!roList || roList.classList.contains("NotEdited")) {
Qualtrics.SurveyEngine.setEmbeddedData(
"Q14_rankfinal",
""
);
return;
}

// Read rank order directly from the ranked list
var rankedItems = roList.querySelectorAll("li");

rankedItems.forEach(function (li, index) {
//var label = li.innerText.trim(); this line included the rank number which i don't need and so this is trimmed out in the below version
var label = li.innerText.replace(/^\d+\s*/, "").trim();

Qualtrics.SurveyEngine.setEmbeddedData(
"Q14_rank" + (index + 1),
label
);

rankedLabels.push(label);
});

Qualtrics.SurveyEngine.setEmbeddedData(
"Q14_rankfinal",
rankedLabels.join(", ")
);

// console.log('Q14_rankfinal: ' + rankedLabels.join(", "))
// === end of old code ===

});