Deselecting a radio button | XM Community
Solved

Deselecting a radio button


Userlevel 1
Badge
I am working on a Qualtrics question with radio buttons. There is a condition where I need to deselect an already selected radio button. It seems that a class named 'q-radio' changes to class named 'q-radio q-focused q-checked' is applied to the radio button when it is selected. Thus, the radio button attributes like checked and disabled aren't working. Is there a way by which I can deselect the radio button using javascript or JQuery?
icon

Best answer by srane 25 July 2018, 18:16

View original

12 replies

Userlevel 6
Badge +6
This is undocumented but works. It could break at anytime but I doubt it will.

```javascript
Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(choiceId, false);

```
Userlevel 1
Badge
Actually, the question doesn't have a single row of radio buttons but a 5x5 matrix of radio buttons. In each row, the user can select one radio button. I want to be able to deselect a radio button in the last row (5th row). The answer that you've posted works for just a single row of radio buttons. If there is a way to use this same format to deselect a column in the 5th row of the matrix, then do let me know.
Userlevel 6
Badge +6
> @srane said:
> Actually, the question doesn't have a single row of radio buttons but a 5x5 matrix of radio buttons. In each row, the user can select one radio button. I want to be able to deselect a radio button in the last row (5th row). The answer that you've posted works for just a single row of radio buttons. If there is a way to use this same format to deselect a column in the 5th row of the matrix, then do let me know.

```javascript
Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(rowId, choiceId, false);
```
Userlevel 1
Badge
It would be of great help if you could explain me how the rowId and choiceId looks like. I tried inspecting the element but am not sure where I am going wrong as the id which I tried doesn't seem to work.

This is what I've done:
Qualtrics.SurveyEngine.registry[this.questionId].setChoiceValue('5', i, false);

'i' is the variable that I am using in the for loop to deselect all the choiceIds.
Userlevel 1
Badge
Well, I have realized a mistake that I was making previously. The solution given by @mattyb513 works perfectly. The only thing that needs to be done is that 'this.questionID' needs to be stored in a variable first.

Code:
var qid = this.questionId;
Qualtrics.SurveyEngine.registry[qid].setChoiceValue(5, 1, false); //This statement deselected the 1st radio button of 5th row

Thanks!
Userlevel 6
Badge +6
Sure! Here's a working example:

https://qualtricssfi.az1.qualtrics.com/jfe/preview/SV_e5MFoByyrznO61v?Q_SurveyVersionID=current&Q_CHL=preview

I've attached the qsf.
Userlevel 5
Badge +7
I agree with @srane, this documentation is incomplete without explaining what the choiceId and the rowId look like. The questionId is _QR~201~1~1_, but what does the rowId and choiceId look like in practice? The API documentation says both should be strings, but I see multiple people on here using 1's, though that doesn't tick my radio button. @mattyb513, could you shed some light on this for me? Much appreciated, thank you!
Userlevel 6
Badge +6
@srane in your case the question ID is actually QID201. 1 is the row id. 1 is the choice ID.

The code I gave has no documentation to my knowledge.
Userlevel 5
Badge +7
Thanks @mattyb513! The documentation I was referencing is this: https://s.qualtrics.com/WRAPI/QuestionAPI/classes/Qualtrics%20JavaScript%20Question%20API.html, though it's requiring you to bring in some prior knowledge such as what the rowId and ChoiceId are. setChoiceValue should be on there, though I am using this method.

let that = this;
that.setChoiceValue([choiceId],[SubId],[Value]);

Take note the parameters are different. And I haven't gotten this particular function to work yet. I've used others, but this one is giving me trouble. Just wanted to share the knowledge if it wasn't known!
Userlevel 5
Badge +7
@srane, did you ever get this method to work? I'm doing an identical process and I can not for the life of me get these radio buttons to cooperate. I also have a matrix with 5 choices per line and none will let me set their value. I would greatly appreciate it if you could share your findings, thanks!
Userlevel 4
Badge +18
@JeremyK - This code works:-

var that = this;
that.setChoiceValue(i,j,true);

Where:-
i = Statements code
j = Scale Points code
Please note that if you are incrementing i & j, you must have codes in same way in Qualtrics otherwise script wouldn’t work. If in Qualtircs you have answer codes not in acceding order you can use function "setChoiceValueByRecodeValue" in same way.
@mattyb513 Hello, thanks for your script. However, I still have a question, How did you create the deselect button ? I saw that in the text editor, but I have no idea how to create that button. Thanks in Advance!

Leave a Reply