mardi 23 décembre 2014

Issue on Deselecting All Checkbox on Un checking one of Child

I am trying to use jquery to check all checkboxes using below code which working fine on toggling select all on check and un check the slectAll


Now I want to uncheck the slectAll in case of a situation if a user un-check one of the ieldset checkboxes. I tried this code



$.each($("input[name='numbers']:not(:checked)"), function () {
$('input:checkbox[name=slectAll]').prop("checked", false);
});


but it didn't do the job!



<input id="boxid" type="checkbox" name="slectAll">
<label for="boxid">Select All</label>
<fieldset id="group_1">
<input type="checkbox" name="numbers[]" value="0" />
<input type="checkbox" name="numbers[]" value="1" />
<input type="checkbox" name="numbers[]" value="2" />
<input type="checkbox" name="numbers[]" value="3" />
<input type="checkbox" name="numbers[]" value="4" />
</fieldset>


and the jquery file is



$(function () {
$('input:checkbox[name=slectAll]').change(function () {
if ($(this).is(':checked')) {
$('#group_1').find(':checkbox').prop("checked", true);
} else {
$('#group_1').find(':checkbox').prop("checked", false);
}
});

$.each($("input[name='numbers']:not(:checked)"), function () {
$('input:checkbox[name=slectAll]').prop("checked", false);
});

});


can you please let me know how to fix this? thanks





Aucun commentaire:

Enregistrer un commentaire