JS/Javascript - How to clear a matrix table answers when a check box is clicked | XM Community
Skip to main content

JS/Javascript - How to clear a matrix table answers when a check box is clicked

  • February 19, 2023
  • 3 replies
  • 98 views

Forum|alt.badge.img+3

Hello,
I have a matrix table with carry forward answers (max 9 rows and 2 columns) along with a check box. I would like to clear the answers from the matrix table, if the check box is clicked. I have included a screen shot of my page. How can I do this? Any help will be greatly appreciated.
Thank you and All the best
2023-02-18.png

3 replies

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • February 19, 2023

FJSandy
I believe checkbox is missing from your screenshot and for such checkbox you will have to use side by side question type.
Additionally you can do your usecase via custom coding.
Hope it helps!


Forum|alt.badge.img+3
  • Author
  • 7 replies
  • February 19, 2023

Deepak
The checkbox in the screenshot is the button at the bottom labeled "Preferred not to share"


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+44
  • 1549 replies
  • February 20, 2023

FJSandy
Thank you for the clarification. You can include the below code in the multiple-choice question Javascript section.
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var qid= this.questionId;
jQuery('#'+qid).change(function(){
var values = jQuery('#'+qid+'-1-label')[0].attributes.class.value;
if(values=='MultipleAnswer  ChoiceTextPositionLeft q-checked'){
var n= jQuery('td').find('input').length;
for(let i=0;i jQuery('td').find('input')[i].value = '';
}
}
});
});
Hope it helps!


Leave a Reply