Checkboxes - automatically setting all options if the "All" checkbox is ticked | XM Community
Skip to main content
Question

Checkboxes - automatically setting all options if the "All" checkbox is ticked

  • May 4, 2023
  • 2 replies
  • 101 views

Forum|alt.badge.img+2

Hi, just wondering if someone can help, I have a multiple choice question and I am allowing multiple answers …

Is it possible that if a user selects the “All Applications” checkbox, that all the other checkboxes (with the exception of the Other option) are ticked automatically?

 

 

2 replies

Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • May 5, 2023

Yes, we can use JS click event on the option and check if the checked property is true or false; accordingly make other options check/ uncheck.


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • May 5, 2023

Try adding the below to the OnReady section of the question’s JavaScript:

var checkbox = '#'+this.questionId+' input[type="checkbox"]';

jQuery(checkbox).change(function(){

if (jQuery(checkbox).eq(0).prop("checked") == true) {

jQuery(checkbox).eq(1).prop({'checked':true, 'disabled':true});
jQuery(checkbox).eq(2).prop({'checked':true, 'disabled':true});
jQuery(checkbox).eq(3).prop({'checked':true, 'disabled':true});
jQuery(checkbox).eq(4).prop({'checked':true, 'disabled':true});

}else{

jQuery(checkbox).eq(1).prop({'disabled':false});
jQuery(checkbox).eq(2).prop({'disabled':false});
jQuery(checkbox).eq(3).prop({'disabled':false});
jQuery(checkbox).eq(4).prop({'disabled':false});

}

});