Select maximum amount of choices in multiple choice | XM Community
Solved

Select maximum amount of choices in multiple choice

  • 22 August 2018
  • 9 replies
  • 411 views

Badge +1
Hey guys! I know there is validation that doesn't allow a respondent to proceed if he/she has selected more than the amount I limit for him to choose. However, my problem is that I want them to be able to choose up to three choices, but if they click a fourth either qualtrics doesn't let them or another option becomes unclicked.
Is there any way to do this easily?
icon

Best answer by NiC 22 August 2018, 19:33

View original

9 replies

Userlevel 7
Badge +27
Not easily. You would have to write a JavaScript with event handlers to do it.
Userlevel 7
Badge +27
If you want the error to be shown after next is selected
Yes, there is a way in Qualtrics by Default
!
You can give it the atleast or atmost values

where as if you want it to be the instant the option is selected

this.questionclick = function(event,element){
var selectedchoice=this.getSelectedChoices();
if(selectedchoice.length==4){
jQuery("#NextButton").click()
}
}
and you need to add the validation here too
!
also change the max number from "3" to whatever you like in the code given above.
and place it in onload function
but it should be the same in validation and code
Hello @GabrielRibeiro ,

Paste the following code in the js(onload) of the multi choice question:

this.questionclick = function(event,element){
var selectedchoice=this.getSelectedChoices();
if(selectedchoice.length==3){
jQuery("#"+ this.questionId +" input:checkbox:not(:checked)" ).attr("disabled", true);
}else{
jQuery("#"+ this.questionId +" input:checkbox:not(:checked)" ).attr("disabled", false);
}
}

The above code will allow the respondent to change the response after they un-check the previous option
Userlevel 7
Badge +27
> @Shashi said:
> Hello @GabrielRibeiro ,
>
> Paste the following code in the js(onload) of the multi choice question:
>
> this.questionclick = function(event,element){
> var selectedchoice=this.getSelectedChoices();
> if(selectedchoice.length==3){
> jQuery("#"+ this.questionId +" input:checkbox:not(:checked)" ).attr("disabled", true);
> }else{
> jQuery("#"+ this.questionId +" input:checkbox:not(:checked)" ).attr("disabled", false);
> }
> }
>
> The above code will allow the respondent to change the response after they un-check the previous option

isn't this redundant ? he can change the answer through my code , is there anything new you are bringing to the table ?
Badge +1
Thanks @NiC_Ugam and @Shashi both codes worked! Just a quick Q: in the options, one of them is "none of the above", which in qualtric's own software automatically unclicks other options if it is chosen. However, with the codes whenever they should click on none of the above it can't because its limited to 3. Is there any way to add a line of code that if they click a specific option it unlicks the rest?
Userlevel 6
Badge +18
> @NiC_Ugam said:
> If you want the error to be shown after next is selected
> Yes, there is a way in Qualtrics by Default
> !
> You can give it the atleast or atmost values
>
> where as if you want it to be the instant the option is selected
>
> this.questionclick = function(event,element){
> var selectedchoice=this.getSelectedChoices();
> if(selectedchoice.length==4){
> jQuery("#NextButton").click()
> }
> }
> and you need to add the validation here too
> !
> also change the max number from "3" to whatever you like in the code given above.
> and place it in onload function
> but it should be the same in validation and code
>
>

Hey @GabrielRibeiro ,

Put 1 in at least box....
Hey @GabrielRibeiro ,

This solution will uncheck other(last) option if three options are selected
Paste the following code in the js(onload) of the multi choice question:

var lastChecked;
var $checks = jQuery('input:checkbox').click(function(e) {
var numChecked = $checks.filter(':checked').length;
if (numChecked > 3) {
lastChecked.checked = false;
}
lastChecked = this;
});
Badge +1
@Shashi thanks! However, what I have is basically 5 options and a 6th which is none of the above. I want them to be able to select max three, but to be able to select "a fourth" only if its none of the above because then it will delesect the other three.
Is this even possible at all?
Thanks!
Userlevel 7
Badge +20
You can do this through custom validation.
- Do not set any limit for selecting an option
- Make your "None of the above" option as exclusive: https://www.qualtrics.com/support/survey-platform/survey-module/editing-questions/formatting-answer-choices/
- Add custom validation (as shown below)
!

Leave a Reply