Clear specific carousel question if user selects back chevron | XM Community
Question

Clear specific carousel question if user selects back chevron

  • 24 April 2024
  • 4 replies
  • 31 views

Badge +3

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 . . .


4 replies

Userlevel 1
Badge +6

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('input[type="radio"], input[type="checkbox"], input[type="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 (inputs[i].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

        });

    };

});


 

Badge +3

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!

Userlevel 1
Badge +6

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

Badge +3

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

Leave a Reply