I have many checkboxes with the multiple values, many checkboxes have the same value and when I click on one checkbox all other checkboxes with that value is also checked/unchecked. That is what the fiddle code does now. 1) But in addition I need to keep an updated array of unique values of checked checkboxes to be used elsewhere as an index to an associate PHP array. and 2) I need to limit the number of checked checkboxes with unique values.
Here is what I have so far:
Checkbox selection based upon values:
<div class="div1">
<input type="checkbox" class="chkbox" value="101"> This is 101
<input type="checkbox" class="chkbox" value="102"> This is 102
<input type="checkbox" class="chkbox" value="103"> This is 103
<input type="checkbox" class="chkbox" value="110"> This is 110
</div>
<div class="div2">
<input type="checkbox" class="chkbox" value="102"> This is 102
<input type="checkbox" class="chkbox" value="101"> This is 101
<input type="checkbox" class="chkbox" value="103"> This is 103
</div>
<div class="div3">
<input type="checkbox" class="chkbox" value="110"> This is 110
<input type="checkbox" class="chkbox" value="102"> This is 102
</div>
$(".chkbox").change(function() {
var val = $(this).val();
if( $(this).is(":checked") ) {
$(":checkbox[value='"+val+"']").attr("checked", true);
}
else {
$(":checkbox[value='"+val+"']").attr("checked", false);
}
});
Aucun commentaire:
Enregistrer un commentaire