JQuery Addup All Checkboxes
JQuery to Add-up all checkboxes and Hidden Field
by Good Muyis
HTML
<div class="field field-name-field-property-price field-type-number-integer field-label-inline clearfix col-md-5">
<div class="field-label">Property Price (₦): </div>
<div class="field-items">
<div class="field-item even">1000</div>
</div>
</div>
<div class="field field-name-field-service-charge field-type-number-integer field-label-inline clearfix col-md-5">
<div class="field-label">Service Charge (₦): </div>
<div class="field-items">
<div class="field-item even">1000</div>
</div>
</div>
<div class="available-services">
<input type="checkbox" id="basic_single" name="basic_single" value="400">
<input type="checkbox" id="basic_double" name="basic_double" value="500">
<input type="hidden" id="basic_doubles" name="basic_doubles" value="1000">
</div>
<input id="stotal" placeholder="Your Names">
JavaScript
$('.available-services input:checkbox').change(function() {
var total = 0;
$('input:checkbox:checked').each(function() {
total += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val());
});
var charges = $('.field-name-field-service-charge .field-item').text();
var price = $('.field-name-field-property-price .field-item').text();
total = total + parseInt(price) + parseInt(charges);
$("#stotal").val(total);
console.log("Js Loaded Update: " + total + " + " + parseInt(price) + " & " + parseInt(charges));
});