Auto select option in multiple choice question | XM Community
Solved

Auto select option in multiple choice question

  • 22 May 2020
  • 2 replies
  • 144 views

Userlevel 2
Badge +2

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.

icon

Best answer by SurajK 23 May 2020, 00:07

View original

2 replies

Userlevel 5
Badge +4

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)}
});

Userlevel 2
Badge +2

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("input[type=checkbox]:not(input[id='QR~QID172807693~6']):checked").length;

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

Leave a Reply