javascript - How to uncheck a checkbox when checked option is other than 'All' -
i've multiple checkboxes populated database, except 1 checkbox "all" (used check/uncheck other checkboxes onclick)
when options checked , if option other 'all' unchecked checkbox of should unchecked.
when option checked except 'all' 'all' should checked. how proceed?
my code:
<script> $(document).ready(function () { ('#check').append('<input type="checkbox" id="checkall" name="mycheckbox[]" value="all" > </input>' + "all" ); //'datadb' data db in json array //datadb={'apple','banana','orange'} $.each(datadb, function(i, fruit) { $('#check').append('<input type="checkbox" name="mycheckbox[]" class=".chk" value="' + fruit + '" > </input>' + fruit ); $('#check').append('<br/>'); } }); </script> <script> $(document).ready(function() { $("#checkall").click(function () { $('input:checkbox').not(this).removeprop('checked'); }); }); </script>
<div id="check" onchange="testingclick()"></div>
how fill function satisfy above 1 , 2
<script> function testingclick(){ var $check_values = $("input[type=checkbox][name='mycheckbox[]']:checked"); var $check_len = $check_values.length; var $total_len = $("input[type=checkbox][name='mycheckbox[]']").length; window.var_multiple_checked = $check_values.map(function(){ return "'" + this.value + "'"; }).get(); temp_checked= window.var_multiple_checked; } </script>
for code.
$('input:checkbox').not(this).prop('checked', this.checked);
try use removeprop instead
$('input:checkbox').not(this).removeprop('checked');
and events of checkbox. hook event.
$(document).ready(function() { $('input:checkbox').click(function () { if ($(this).attr('id') === 'checkall' && $(this).is(':checked')) { $('input:checkbox').not($(this)).removeprop('checked'); } else { $('#checkall').removeprop('checked'); } }); });
Comments
Post a Comment