mardi 3 février 2015

How to unchek a checkbox using jquery when check the other one in a array


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!





Aucun commentaire:

Enregistrer un commentaire