CODE TO DE-SELECT RADIO BUTTON | XM Community
Solved

CODE TO DE-SELECT RADIO BUTTON

  • 20 February 2021
  • 3 replies
  • 204 views

Userlevel 1
Badge

Hi,
Radio button accurately fills-in with background color when clicked. Works great.
However, can someone please share code (non-JavaScript) that will remove the background color of a radio button when the respondent clicks the same answer a second time? A second click on a radio button answer makes the background color disappear.
Not an exciting dilemma, but anyone's help would be greatly appreciated as usual.

I've explored a previous thread on the subject and found this: https://www.qualtrics.com/community/discussion/1387/deselecting-a-radio-button
Code:
var qid = this.questionId;
Qualtrics.SurveyEngine.registry[qid].setChoiceValue(5, 1, false); //This statement deselected the 1st radio button of 5th row

However, I do not have rights to JavaScript, and my solution would be somewhat different because I have a single column of 12 rows of radio buttons.
Still need help if you can.

icon

Best answer by ahmedA 21 February 2021, 01:43

View original

3 replies

Userlevel 7
Badge +21

It is not possible to deselect a radio button. You can either provide a "NA" or something like that option or use a multiple choice question, enforcing one choice via validation.

Userlevel 1
Badge

Interesting. Ok. Thanks. Let me work with that.
But . . . just to be clear - since my level of experience is below microscopic, I want to make certain that I've expressed myself properly/correctly before I simply move on. If I'm not mistaken, the thread that I included earlier specifically was about someone wanting to deselect an option and there appeared to be quite a bit of discussion on how it might be accomplished (which, of course, was above my head). You are quite emphatic, and I certainly bow to your experience, but how do you reconcile the conversation in the thread that included references to code solutions? Was it possible to deselect at one point and it has since changed? Not questioning your expertise, but I'm just trying to make certain that I am not asking the wrong question or presenting my need incorrectly.

Userlevel 7
Badge +21

Thanks for those compliments. I just hope my advisor stumbles upon this thread. :-)
Radio buttons can not be deselected, but they can be reset. That's what happening at the backend in the earlier solution. If you inspect a radio/checkbox on the Qualtrics platform, you'll see that the moment you click it, a class gets added to it "q-checked".
I'm not aware of the exact internal functioning, but some process like this could be going on in the background, as soon as Qualtrics registers a radio selection, it updates the page, adds the class and stores the response, i.e. sets the choice value. Since the code you have shared above works, it implies that some sort of refresh/reset is happening to all the choices, i.e. it resets all the choices to unselected, then checks which is set to true and selects that.
This absence of such a basic functionality, I clicked a button by mistake, I want to unselect it. Why can't I do it. Had troubled me for quite a while, so I read upon the history of radio buttons, particularly, why is it called a radio button? It turns out that people didn't give it much tought initially, just adopted what was being used in the desktop platforms those days and now they're scared that if they change it, the general public might get confused.

Leave a Reply