[![enter image description here][1]][1]
i want if check "pilih semua" then total use price "pilih semua"
but if not check "pilih semua " then price += item
please help me
but if not check "pilih semua " then price += item
please help me
this sample
i want if check all then price 1000 not 1900
please help me, please help me, please help me, please help me, please help me, please help me, please help me, please help me, please help me
$(document).ready(function() {
var checkboxes = document.querySelectorAll('input.subOption1'),
checkall = document.getElementById('option1');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].onclick = function() {
var checkedCount = document.querySelectorAll('input.subOption1:checked').length;
checkall.checked = checkedCount > 0;
checkall.indeterminate = checkedCount > 0 && checkedCount < checkboxes.length;
}
}
checkall.onclick = function() {
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = this.checked;
}
}
$('input:checkbox').change(function() {
var total = 0;
var totalkat = 0;
$("input[name='id_kat_lab[]']:checked").each(function() { // iterate through each checked element.
totalkat += isNaN(parseInt($(this).data('harga'))) ? 0 : parseInt($(this).data('harga'));
});
$("input[name='id_item[]']:checked").each(function() { // iterate through each checked element.
total += isNaN(parseInt($(this).data('harga'))) ? 0 : parseInt($(this).data('harga'));
});
$("#totallab").val(totalkat + total);
});
});
https://stackoverflow.com/posts/76002314/edit#
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row gutters">
<div class="col-xl-3 col-lg-3 col-md-3 col-sm-3 col-12 tesrow">
<div class="card tes">
<div class="card-body tes-body" id="kompatibility">
<ul class="list-group m-0 komp">
<li class="liutama" >
Categori 1
</li>
<li class="komp list-group-item d-flex justify-content-between align-items-center">
<input id="option1" name="id_kat_lab[]" type="checkbox" value="1" data-harga="1000" aria-label="...">
All <span class="badge bg-primary rounded-pill">
Rp .1000
</span>
</li>
<li class="komp list-group-item d-flex justify-content-between align-items-center ">
<input class="subOption1" type="checkbox" name="id_item[]" value="1" aria-label="..." data-harga="200" >
chicken <span class="badge bg-primary rounded-pill">Rp. 200
</span>
</li>
<li class="komp list-group-item d-flex justify-content-between align-items-center ">
<input class="subOption1" type="checkbox" name="id_item[]" value="2" aria-label="..." data-harga="400" >
chicken 2 <span class="badge bg-primary rounded-pill">Rp. 400
</span>
</li>
<li class="komp list-group-item d-flex justify-content-between align-items-center ">
<input class="subOption1" type="checkbox" name="id_item[]" value="3" aria-label="..." data-harga="300" >
chicken 3 <span class="badge bg-primary rounded-pill">Rp. 300
</span>
</li>
</ul>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-4 col-12 ">
<div class="input-group">
<span class="input-group-text">
Total
</span>
<input type="number" class="form-control" class="totallab" id="totallab">
</div>
</div>
2
Answers
Just comment
checkAll.onclick
section to get a total =1000
.Just simplified your
JS
.Notice: Your sum of options is not equal to the
Check All
. So if you want the total to be sum of options just replace everyshowTotal();
withshowTotal(priceList);
.