I am generating dynamic checkboxes with the functionality of radiobuttons
var foo = $("#foo");
for (var i = 0; i < 5; i++) {
var descr = $('<br><tr><td><label> TEST_'+i+':</label></td><td colspan="2">' +
'<div class="controls gprs_modbus_checkbox_' + i + '">'+
'<label class="checkbox"><input class="chb" type="checkbox" value="option1" > GSM</label>'+
'<label class="checkbox"><input class="chb" type="checkbox" value="option2" > RTU</label>' +
'<label class="checkbox"><input class="chb" type="checkbox" value="option3" > TCP</label>'+
'</div></td><td></td><td></td></tr>' );
$(descr).insertAfter(foo);
}
var m;
$('.chb').on('click',function() {
m = $(this).closest('div').prop('class').split(' ')[1];
console.log(m);
var checked = $(this).is(':checked');
$('.'+ m +' >label> input[type="checkbox"]').prop('checked',false);
if(checked) {
$(this).prop('checked',true);
}
})
What I am trying to do is that when I click 'GSM', all others 'GSM's should be 'clicked' too. It supposed to react synchronized. But there must still be the possibility to select none of the checkboxes.