philchanet
12/8/2016 - 2:55 PM

Make checkboxes behave like radio buttons (makes it possible to select nothing if needed). Inputs with the same name="" attribute work like

Make checkboxes behave like radio buttons (makes it possible to select nothing if needed). Inputs with the same name="" attribute work like radios of the same group.

$("input:checkbox.exclu").click(function() {
    if ($(this).is(":checked") === true) {
        var group = "input:checkbox[name='" + $(this).prop("name") + "']";
        $(group).prop("checked", false);
        $(this).prop("checked", true);
    } else {
        $(this).is(":checked", false);
    }
});
<tr>
    <td class="text-center"><input type="checkbox" class="exclu" name="engagements[1][]" value="1" checked></td>
    <td class="text-center"><input type="checkbox" class="exclu" name="medias[2][]" value="1"></td>
    <td class="text-center"><input type="checkbox" class="exclu" name="vente[3][]" value="1"></td>
</tr>
<tr>
    <td class="text-center"><input type="checkbox" class="exclu" name="engagements[1][]" value="2"></td>
    <td class="text-center"><input type="checkbox" class="exclu" name="medias[2][]" value="2" checked></td>
    <td class="text-center"><input type="checkbox" class="exclu" name="vente[3][]" value="2" checked></td>
</tr>