How to dynamically display number of selected items in a multiple choice question? | XM Community
Skip to main content

I’d be extremely grateful if someone could help me.

 

I’ve got a multiple choice question where participants can select at least 10 out of 62 selectable answers. For their ease, I’d like to display the number of answers a participant has selected and to do so dynamically, so participants can tell easily how many items they’ve selected before trying to go onto the next page. 

 

I’ve found an old thread which seems to be about a similar thing:

How to display choice count dynamically in question text for likert, single answer question type | XM Community (qualtrics.com)

 

... but I’m very new to JS and I’m not having any luck figuring out how to apply this code to my own situation. I’d be enormously grateful for any guidance on a bit of JS that could collect this information (how many items has a participant selected within this single multiple choice question), and how to embed that number in a bit of text so that participants can see the number updating dynamically when they select answers.

 

Thanks so much, in advance, to anyone who can help! :)

@CluelessAcademic Follow this link to learn how to add JS to your question: https://www.qualtrics.com/support/survey-platform/survey-module/question-options/add-javascript/

This JS code should do the trick

Qualtrics.SurveyEngine.addOnload(function() {
var displayCount = document.createElement('div');
displayCount.id = "countDisplay";
displayCount.style.fontWeight = "bold";
displayCount.style.marginTop = "10px";

var nextButton = document.querySelector('.NextButton');
nextButton.parentNode.insertBefore(displayCount, nextButton);

function updateCount() {
var selectedChoices = jQuery("inpututype='checkbox']:checked").length;
displayCount.innerHTML = "You have selected " + selectedChoices + " out of 62 options.";
}

updateCount();

jQuery("inpututype='checkbox']").on('change', updateCount);
});

 


Nam Nguyen - THANK YOU! It works perfectly. I’m extremely grateful for your help! :)


Nam Nguyen - THANK YOU! It works perfectly. I’m extremely grateful for your help! :)

@CluelessAcademic Glad to know that 👍


Leave a Reply