Set a column of check boxes checked by default in a side-by-side question | XM Community
Skip to main content

Hi,
I am trying to pre-check (i.e. by default) all the check boxes in the same column based on the response from previous question.
In my case, a respondent is first asked to select the services the company provides. If "Bandwidth" is selected, for example, the check boxes under the "Bandwidth" column in the SBS table will all be checked by default.
services.JPGsbs check box.JPGI am a beginner in JavaScript. I found a similar post which could be a possible solution with some amendments. The code from the post:
if("${e://Field/Skill1Included}" > 0) {
jQuery('#'+this.questionId).find('tbody tr').find('.SBS2').find('input[type="checkbox"]').eq(0).prop('checked',true)
}
I've set up some branch logics and embedded data fields for the conditions used in the code, but I don't know what I should change in the jQuery commend to get it working with the columns.
Many thanks!

Hi Harris423 ,
I making below assumptions on
1.Both questions are not randomized
2.Questiona and option structure is same as screenshots.
3."Bandwidth " option will be selected for country option which are not displayed also.
If you have no issues with above assumptions then you can achieve the above request my doing the following:
image.png1.Make a "flag" -named embedded data variable and make sure it is defined before that question block or better at the top .
2.In question having "Bandwidth" option write the following code:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
let ques=document.querySelector(".QuestionBody");
ques.addEventListener("change", function(event) {
 let span=document.querySelectorAll(".Skin label.MultipleAnswer.q-checked, .Skin label.SingleAnswer.q-checked");
for(let i=0;i
if(spanni].innerText=="Bandwidth")
{
Qualtrics.SurveyEngine.setEmbeddedData( 'flag', "1" );
console.log("value matched");
break;
   
}
else
{
console.log("value not matched");

   
}
});

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

Put a page break.
3.In SBS question write the following code:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{

if(parseInt('${e://Field/flag}')==1)




let sbs=document.querySelectorAll(".SBS1.c4")

for(let i=1;i  {
sbsi].childNodes.1].click()
     
  }

}



});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

Hope it resolves your query😊!!


It looks like you should be using a Matrix instead of a Side-by-side. There are a number of benefits in doing so. In general, side-by-side questions should be avoided unless absolutely necessary.
In your case, assuming a matrix, you can carry forward scale points to only show the selected services as scale points in your matrix question. You can then check all the boxes with a simple line of JS:
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#"+this.questionId+" input[type=checkbox]").prop("checked",true);
});


https://community.qualtrics.com/XMcommunity/discussion/comment/54909#Comment_54909Right, a Matrix should be used. We were thinking to make a country dropdown in the first column, so a side-by-side was set up initially.
We also want to show the unselected services, is it possible to specify which column to be checked in the JS you provided?
Thanks a lot!


https://community.qualtrics.com/XMcommunity/discussion/comment/54908#Comment_54908Thanks qualtrics_nerd . I will do some trials with your codes and update what I have got here.


https://community.qualtrics.com/XMcommunity/discussion/comment/54928#Comment_54928Yes, if you carryforward the displayed choices as scale points you can use this JS (Replace QIDxx with the QID of the previous question and there must be a page break between the questions. This assumes that the choice ids match the recodes, which is true unless you've recoded the answers):
Qualtrics.SurveyEngine.addOnload(function() {
var cbs = jQuery("#"+this.questionId+" input[type=checkbox]");
jQuery.each("${q://QIDxx/SelectedChoicesRecode}".split(", "), function(i,val) {
cbs.filter("[id$=\\\\~x"+val+"]").prop("checked",true);
});
});


Leave a Reply