$(document).ready(function() {
$("input[type=checkbox]").on("change", function() {
var tot = 0;
$("input[type=checkbox]:checked").each(function() {
tot += +(this.value);
});
$("#result").text("Total = " + tot);
$('#CRCGCA').val("Total = " + tot)
});
});
<p>Gift Certificate Amount (check one or more)
<br />
<span class="wpcf7-form-control-wrap GRCGA"><span class="wpcf7-form-control wpcf7-checkbox wpcf7-validates-as-required Multiple radio-vertical" id="GRCGA"><span class="wpcf7-list-item first"><label><input type="checkbox" name="GRCGA[]" value="$10.00 Gift Card" /> <span class="wpcf7-list-item-label">$10.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item"><label><input type="checkbox" name="GRCGA[]" value="$20.00 Gift Card" /> <span class="wpcf7-list-item-label">$20.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item"><label><input type="checkbox" name="GRCGA[]" value="$25.00 Gift Card" /> <span class="wpcf7-list-item-label">$25.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item"><label><input type="checkbox" name="GRCGA[]" value="$40.00 Gift Card" /> <span class="wpcf7-list-item-label">$40.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item"><label><input type="checkbox" name="GRCGA[]" value="$100.00 Gift Card" /> <span class="wpcf7-list-item-label">$100.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item"><label><input type="checkbox" name="GRCGA[]" value="$200.00 Gift Card" /> <span class="wpcf7-list-item-label">$200.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item"><label><input type="checkbox" name="GRCGA[]" value="$400.00 Gift Card" /> <span class="wpcf7-list-item-label">$400.00 Gift Card</span>
</label>
</span><span class="wpcf7-list-item last"><label><input type="checkbox" name="GRCGA[]" value="$500.00 Gift Card" /> <span class="wpcf7-list-item-label">$500.00 Gift Card</span>
</label>
</span>
</span>
</span>
</p>
<p>Gift Card Amount: <span class="wpcf7-form-control-wrap CRCGCA"><input type="text" name="CRCGCA" value="" size="8" maxlength="8" class="wpcf7-form-control wpcf7-text" id="CRCGCA" aria-invalid="false" /></span>
</p>
<p id="result"></p>
I am having a problem calculating the total of the checkbox group ( this check box set is multi selectable ( can have one or more picked) I also like to have the total copied to the text box called gift card amount.
HTML:
<p>
Gift Certificate Amount (check one or more)<br />
[checkbox* GRCGA id:GRCGA class:Multiple use_label_element class:radio-vertical "$10.00 Gift Card " "$20.00 Gift Card " "$25.00 Gift Card " "$40.00 Gift Card " "$100.00 Gift Card " "$200.00 Gift Card " "$400.00 Gift Card " "$500.00 Gift Card"]
</p>
Gift Card Amount: [text CRCGCA 8/8 id:CRCGCA]
<p id="result"></p>
JavaScript
$(document).ready(function() {
$("input[type=checkbox]").on("change", function() {
var tot = 0;
$("input[type=checkbox]:checked").each(function() {
tot += +(this.value);
});
$("#result").text("Total = " + tot);
$('#CRCGCA').val("Total = " + tot)
});
});
Your checkboxes have values like
$25.00 Gift Card
. You need to change it to a number, e.g.25
.If you insist on using your current markup you could get the actual number using
Though someone who's good at regexp can probably figure out something prettier.