Good morning, I have a 'Attendance' form where there is a checkbox for each service.
CurrentlyIcangettheidofeachselectedcheckbox,putitinanarrayandprintthisarray,butthat'snotmygoal.Iwouldlikeforeachcheckedcheckboxtocapturethevalueoftheserviceandincrementinthe'Total'input.
Myformcodelookslikethis:
<?phpforeach($servicosas$servico):?><labelclass="checkbox-inline">
<input type="checkbox" name="servico[]" value="<?=$servico['id']?>">
<?=$servico['descricao'] .' R$ ' . number_format($servico['valor'],2,',','.'); ?></label>
</br>
<?php endforeach?>
<h2>Total</h2>
<input type="number" name="totalValor" disabled>
And my checkbox id capture code looks like this:
<script>
$(document).ready(function() {
var ids = []
$(":checkbox").change(function () {
if ($(this).is(":checked")) {
ids.push($(this).val());
$("#idServicos").text(ids);
alert(ids);
}
});
});