Clear specific carousel question if user selects back chevron | XM Community
Skip to main content

If a respondent uses the “<” chevron to navigate to  / revisit a previously answered question, is it possible with Java or CSS to clear their response to that question (so that they may re-answer it)?

I haven’t been successful so far . . .

Hi @Chipper 

Unfortunately, it's not possible to achieve this functionality solely with JavaScript or CSS because the browser's history navigation (such as using the "<" chevron) doesn't trigger JavaScript events or allow direct manipulation of form inputs via CSS.

But you can build in a clear responses button if you want that the person respondent the answers

 

Qualtrics.SurveyEngine.addOnload(function() {

    const quest = this;

    const qc = quest.questionContainer;

    var questionId = this.questionId;

    var inputs = qc.querySelectorAll('inputltype="radio"], input=type="checkbox"], inputhtype="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++) {

            inputsti].checked = false;

            if (inputs.i].type === "text") {

                inputsii].value = "";

            }

        }

        qc.querySelectorAll(".q-checked").forEach((item) => {

            item.classList.remove("q-checked");

        });

        qc.querySelectorAll("select").forEach((select) => {

            select.selectedIndex = -1; // Clear selected option

        });

    };

});


 


Hi, @RickB,

Thanks so much -- that’s a nice option! It does the job to clear all options -- it’s challenging because when clearing all options, it doesn’t allow the respondent to re-select a previously selected option.

Your code is great -- I think the carousel functionality isn’t quite what I hoped.

Thanks very much again!


Hi @Chipper 

 

I see what you mean. When you click first on a other answer you can choice all answer again. 

 

But i understand that this i not a good solluction

Hope you found a good answer for this problem


Thanks, @RickB. You’re code was a great idea! Thanks for your help and support.


Leave a Reply