2
I have a checkbox group and I need to get the checkbox that the user clicked, with this, I need to manipulate others who are from the same group.
<input type="checkbox" name="grupo[1][1][]" value="A" data-unique="0"> A
<input type="checkbox" name="grupo[1][2][]" value="B" data-unique="0"> B
<input type="checkbox" name="grupo[1][3][]" value="C" data-unique="0"> C
<input type="checkbox" name="grupo[1][4][]" value="D" data-unique="1"> D
<input type="checkbox" name="grupo[2][1][]" value="A" data-unique="0"> A
<input type="checkbox" name="grupo[2][2][]" value="B" data-unique="0"> B
<input type="checkbox" name="grupo[2][3][]" value="C" data-unique="0"> C
<input type="checkbox" name="grupo[2][4][]" value="D" data-unique="1"> D
On another checkbox listing I have done so:
$('input[name="grupo[]"]').click(function() {
var $this = $(this);
var is_unique = $this.data('unique');
var is_checked = $this.is(':checked');
var grupo = $('input[name="grupo[]"]');
if(is_unique == '1') {
grupo.each(function() {
$(this).prop("checked", false);
$(this).prop("disabled", is_checked);
$this.prop("checked", is_checked);
$this.prop("disabled", false);
});
}
});
Only in this new listing I have this multidimensional array and so it doesn’t work, does anyone have any tips to help me?
Try to change
$('input[name="grupo[]"]')
for$('input[name^="grupo["]')
and see if that solves your problem.– Felipe Avelar
It didn’t work. I’m not sure what the
^
and another, I think that way will not catch the group that I still need to manipulategrupo[x][y][]
– Marcelo Diniz
o is to say a name that starts with group[, in case he should take all elements with that name...
– Felipe Avelar