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 . . .
Clear specific carousel question if user selects back chevron
Hi
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
});
};
});
Hi,
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
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,
Leave a Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.