jquery - Sum Checkboxes without POSTING values - Javascript -
i've had around find definitve answer.
basically, have total, id im trying automatically update once checkbox clicked.
p style="font-size: 1.2em; font-weight: bold;"><b>total cost:</b> £<input value="0.00" readonly="readonly" type="text" id="total"/></p>
the checkbox have simple value such 1.50 or similar. (these dynamic) so
<input name="product" value="<?php echo $count*0.50 ?>" type="checkbox">
this may simple! im not hands on javascript
handling both checking , unchecking box update sum input working jsbin example, assuming using jquery.
var sum = 0; var total = $('#total'); var cbox = $('.cbox'); $('.cbox').on('change', function() { if ($(this).prop('checked')) { sum += parsefloat($(this).val()); updatetotal(); } else { sum -= parsefloat($(this).val()); updatetotal(); } }); function updatetotal() { total.val(sum); }
Comments
Post a Comment