3
Good morning, I have a 'Care' form where there is a checkbox for each service.
Currently I can get the id of each checkbox selected, put in an array and print this array, but that’s not my goal. I would like for each selected checkbox to capture the service value and increment in the 'Total' input'.
My form code looks like this:
<?php foreach($servicos as $servico): ?>
<label class="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 catch code is like this:
<script>
$(document).ready(function() {
var ids = []
$(":checkbox").change(function () {
if ($(this).is(":checked")) {
ids.push($(this).val());
$("#idServicos").text(ids);
alert(ids);
}
});
});
Perfect Sergio, it worked here. Thank you very much for your attention and I’m sorry for disturbing you so much. = D
– João Paulo Siqueira