如何在检查数组中的另一个时使用jquery取消选中复选框

问题描述:

Hi guys I have a "datatable" with the following checkboxes on it:

<input type="checkbox" name="total_balance[]"  id="total_balance" class="total_balance" value="<?= $balance['supplierID'] ?>" />

<input type="checkbox" name="no_payment[]"  id="no_payment" class="no_payment" value="<?= $balance['supplierID'] ?>" />

That is a loop, so I've hundred of the same names but with different values by row. So what I want is when I check the total_balance[] that has the value=1, for example, it's uncheck, if is checked, the no_payment[] with value=1, and so on.. like if I click the total_balance[] with value=32, uncheck the no_payment with value=32...

How to I do that in jquery??

I've tried like that:

$('input[name="total_balance"]').change(function() {
        console.log(this.value);
        var val = this.value;
        $('input:no_payment[value="' + val + '"]').attr('checked', false);
     });


      $('input[name="no_payment"]').change(function() {
        console.log(this.value);
        var val = this.value;
        $('input:total_balance[value="' + val + '"]').attr('checked', false);
     });

but doesn't work

tks!

got it:

$('.total_balance').click(function() {
        var val = this.value;
        $('.no_payment[value="' + val + '"]').attr('checked', false);
     });


      $('.no_payment').click(function() {
        var val = this.value;
        $('.total_balance[value="' + val + '"]').attr('checked', false);
     })