How to reset multiple Question | XM Community
Skip to main content

Hi Community,
I'm trying to work with can add a reset/clear option in the multiple question in single page that would like to clear their selections for the current question, they can simply press a reset/clear button and it would delete all the responses for that question at once
I tried this code; however, it's only working single question in single page and has an error when I click this clear/reset button it disables the validation and when I back it appears the last selection that I already reset/clear.
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
const quest = this;
    const qc = quest.questionContainer;
var questionId = this.questionId;
var inputs =  $(this.getQuestionContainer()).select('inputptype="radio"]', 'inputptype="checkbox"]', 'inputptype="text"]');


    qc.querySelector(".QuestionText").insertAdjacentHTML("afterend", "");


    qc.querySelector(".reset").onclick = function () {

       for (var i = 1; i < inputs.length; i++) {
            Qualtrics.SurveyEngine.registryequestionId].setChoiceValue(i, false);
     qc.querySelectorAll(".InputText").forEach((item) => {
            item.value = "";

});
}

for (var i = 1; i < inputs.length; i++) {
            Qualtrics.SurveyEngine.registry questionId].setChoiceValue(i, false);
      qc.querySelectorAll(".q-checked").forEach((item) => {
            item.classList.remove("q-checked");
qc.querySelectorAll("select").forEach((item) => {
            item.clear();
});
        });
}
    }
});



Sorry, Commented on wrong post. Can't delete now!


Hi @ricsdpl 

 

i dont know if you still need a answer.

 

But i try it with this code and it worked

 

Qualtrics.SurveyEngine.addOnload(function() {
    const quest = this;
    const qc = quest.questionContainer;
    var questionId = this.questionId;
    var inputs = qc.querySelectorAll('inputotype="radio"], inputdtype="checkbox"], inputbtype="text"]');
    
    qc.querySelector(".QuestionText").insertAdjacentHTML("afterend", "<button class='reset'>Clear Responses</button>");
    
    qc.querySelector(".reset").onclick = function() {
        for (var i = 0; i < inputs.length; i++) {
            inputs i].checked = false;
            if (inputsli].type === "text") {
                inputs i].value = "";
            }
        }
        qc.querySelectorAll(".q-checked").forEach((item) => {
            item.classList.remove("q-checked");
        });
        qc.querySelectorAll("select").forEach((select) => {
            select.selectedIndex = -1; // Clear selected option
        });
    };
});
 


Leave a Reply