You can use the code below for a simpler understanding:
$('select#role').on('change', function (e) {
var optionSelected = $("option:selected", this),
selectedVal = this.value;
if(selectedVal == "admin") {
$(".gestionSupervision").prop('checked', true);
} else {
$(".gestionSupervision").prop('checked', false);
}
}).change();
Demo Screenshot
Or you can shorten the code above:
$('select#role').on('change', function (e) {
var selectedVal = $(this).find('option:selected').val();
$(".gestionSupervision").prop('checked', selectedVal == "admin");
}).change();
Demo Screenshot
source
share