Skip to content

Instantly share code, notes, and snippets.

@mattbloomfield
Created July 10, 2018 16:20
Show Gist options
  • Save mattbloomfield/6e8c45210e185b08ed6d7477b1f16f66 to your computer and use it in GitHub Desktop.
Save mattbloomfield/6e8c45210e185b08ed6d7477b1f16f66 to your computer and use it in GitHub Desktop.
var previousAnswer ="";
Qualtrics.SurveyEngine.addOnload(function() {
var questionId = this.questionId;
this.questionclick = function(event, element) {
if (element.type == 'radio') {
var options = document.querySelectorAll('.q-checked');
for (var i = 0; i < options.length; i++) {
var ansArr = options[i].htmlFor.split('~');
var ansStr = ansArr[2] + '_' + ansArr[3];
if (ansStr !== previousAnswer) {
previousAnswer = ansStr;
uncheckAllExcept(questionId, [ansArr[2], ansArr[3]]);
break;
}
}
}
}
});
function uncheckAllExcept(questionId, chosen) {
for (var i = 1; i < 4; i++) {
for (var j = 1; j < 4; j++) {
Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(i,j, false);
}
}
Qualtrics.SurveyEngine.registry[questionId].setChoiceValue(chosen[0], chosen[1], true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment