Auto select option in multiple choice question | XM Community
Skip to main content

I have multiple response with below 6 options. Now, I want to auto-select "All of the above" option if a respondent select all the responses.
Brand A
Brand B
Brand C
Brand D
Brand E
All of the above.

Write the below code in adOnReady function,

jQuery('input[type="checkbox"]').change(function(){
if (jQuery('input[type="checkbox"]').eq(0).is(":checked") && jQuery('input[type="checkbox"]').eq(1).is(":checked") && jQuery('input[type="checkbox"]').eq(2).is(":checked") && jQuery('input[type="checkbox"]').eq(3).is(":checked") && jQuery('input[type="checkbox"]').eq(4).is(":checked"))
{jQuery('input[type="checkbox"]').last().prop('checked',true)}
else{jQuery('input[type="checkbox"]').last().prop('checked',false)}
});


Thanks Suraj. I managed to find solution for this as well. :)
I got this using below code.

this.questionclick = function(event,element)
{
   var selectorChecked = jQuery("inputptype=checkbox]:not(inputpid='QR~QID172807693~6']):checked").length;

   if (selectorChecked > 0)
   {
      if (selectorChecked == 5)
      {
         this.setChoiceValue(6,1)
      }
   }      
}


Leave a Reply