Side by Side Exclusive Answer | XM Community
Skip to main content

I have a side by side table with a multichoice column. I’d like to make code 3 exclusive.

I’ve got the below which unchecks codes 1 and 2, if code 3 has been selected, but in order to select codes 1 or 2 again, I need to unselect code 3 first.

Also, below I’m relying on the other codes being less than code 3 i.e. codes 1 and 2 in this case - so if my exclusive code isn’t the last code, then I assume I’d need to do a gt line too.

Is there a less clunky way of doing this?

n.b. I have other sets of multichoice columns, so just want the below to target SBS2

Qualtrics.SurveyEngine.addOnReady(function() 
{

jQuery('#'+this.questionId+' tbody tr.Choice').click(function(){
if(jQuery(this).find('td.SBS2:eq(2)').find('inputftype="checkbox"]').is(':checked'))
{
jQuery(this).find('td.SBS2:lt(2)').find('inputftype="checkbox"]').prop('checked',false)
}
});

 

Hi,

Try this :

Qualtrics.SurveyEngine.addOnReady(function() 
{

function exclusiveCheckboxes() {
let rows = document.querySelectorAll('tr.Choice');

rows.forEach(row => {
let checkboxes = row.querySelectorAll('td.SBS2 input[type="checkbox"]');

checkboxes.forEach((checkbox, index) => {
checkbox.addEventListener('change', function() {
if (index === 2 && checkbox.checked) {
checkboxes.forEach((cb, i) => {
if (i !== 2) {
cb.checked = false;
}
});
} else if (index !== 2 && checkbox.checked) {
checkboxes[2].checked = false;
}
});
});
});
}

exclusiveCheckboxes();

});

 


Hi,

Try this :

Qualtrics.SurveyEngine.addOnReady(function() 
{

function exclusiveCheckboxes() {
let rows = document.querySelectorAll('tr.Choice');

rows.forEach(row => {
let checkboxes = row.querySelectorAll('td.SBS2 input[type="checkbox"]');

checkboxes.forEach((checkbox, index) => {
checkbox.addEventListener('change', function() {
if (index === 2 && checkbox.checked) {
checkboxes.forEach((cb, i) => {
if (i !== 2) {
cb.checked = false;
}
});
} else if (index !== 2 && checkbox.checked) {
checkboxes[2].checked = false;
}
});
});
});
}

exclusiveCheckboxes();

});

 

Perfect - thank you


Leave a Reply