How to clear selected options when user uses back button | XM Community
Skip to main content

Hello,
I'm looking to clear selected options when the respondent clicks the 'back' button.
It seems that the choices are 'labels' on Qualtrics back end.
I realize that when the option is selected, there is a new 'q-checked' class that is added. Hence I've been looking for ways to remove that class following the various suggestions here (html - Remove CSS class from element with JavaScript (no jQuery) - Stack Overflow), but it doesn't seem to work.
See one example screen capture below.
There always seems to be a TypeError, something like: "Cannot set properties of null (reading classList)"
Could somebody please help?
javaissue.pngMany thanks in advance!

Hello,
Here's some javascript which unselects all choices when the page is hit. So if they select some options then click the back button then this code will clear those options when they reach that page again, forcing them to re-complete the question. Hope this helps!

Qualtrics.SurveyEngine.addOnReady(function()
{
this.setChoiceValue(1,false)
this.setChoiceValue(2,false)
this.setChoiceValue(3,false)
this.setChoiceValue(4,false)
this.setChoiceValue(5,false)
})

I set it for 5 options but you can add more by just changing the number.


Thank you so much StephH72!!
Works like a dream!
Just a follow-up question - the unselect script you shared works on its own, but doesn't seem to work with the other script I have (which is used to auto-advance to the next page if the option - a button in this case - is clicked).
Both of them work separately, but the 'unselect option' script doesn't work when I add the 'auto-advance' script. Might you know what I'm doing wrong?
java2.pngThanks so much in advance!


Actually it is working now! Not sure what was the issue, but I just added one of the scripts under addOnReady instead. Thanks again for your help!!


https://community.qualtrics.com/XMcommunity/discussion/comment/42103#Comment_42103Hi Steph,

This doesn't seem to work. Do you know if anything has changed? My question a matrix radio button question, I'd like to clear all responses from that question when the user hits back button


Leave a Reply