Clear matrix answered on checkbox click and vice versa | XM Community
Skip to main content
Hey everyone!



I have a questionaire, where respondents can choose to either fill a matrix or check a checkbox, like on the picture below:



!



Now, I want to enable, that when someone checks the "I do not want feedback" box, any potential selcetion in the matrix above gets removed. I have the following code so far:





Qualtrics.SurveyEngine.addOnReady(function()

{

/*Place your JavaScript here to run when the page is fully displayed*/

var qid = this.questionId;

jQuery("input[name='QR~QID57~1']").change(() => {

for (var i = 1; i <= 3; i++) {

for (var j = 1; j <= 6; j++) {

Qualtrics.SurveyEngine.registry[qid].setChoiceValue(i, j, false);

}

}

});

});





However, this doesn't work, every time I check the checkbox now, I get the following error:



!



Thank you!
Try changing it to this:

```

Qualtrics.SurveyEngine.addOnReady(function() {

var qobj = this;

jQuery("input[name='QR~QID57~1']").change(() => {

jQuery("#"+qobj.questionId+" input[type=radio]").each(function() {

var splitId = this.id.split("~");

qobj.setChoiceValue(splitId[2], splitId[3], false);

});

}

});

```
I still get the same error. It's really strange, even when I totally "unroll" the loop, and hardcall setChoiceValue(1, 1, false) etc X times, it gives me the mistake. I am very much confused.
> @rrump said:

> I still get the same error. It's really strange, even when I totally "unroll" the loop, and hardcall setChoiceValue(1, 1, false) etc X times, it gives me the mistake. I am very much confused.



The code I posted worked for me. The only difference was I didn't hard code the checkbox reference when I tried it. Please provide more information:

1. Post your complete code in fences, like:

\\`\\`\\`

your code goes here

\\`\\`\\`

2. Does the error display when you select the checkbox or when the page loads?

3. Post of block preview link to the question.
Hey!



1. I literally reused your code 1:1 right now. I also tried different version, where I trigger it from a button instead of a jQuery Event (thought, maybe the mistake could be there), no difference.



2. Only once the checkbox has been checked, not on page load.



3. https://mtecethz.eu.qualtrics.com/jfe/preview/SV_7Nx0rLEbrHTmYpD/BL_blsZkJvPnBxs2Rn?Q_SurveyVersionID=current - Thank you so much already
@rrump,



I tried it on a Likert where it works. It doesn't work on a Bipolar. They should be the same, but there appears to be a problem within the bipolar question object. You should probably report it Qualtrics Support.

Leave a Reply