I have a form where based on checkbox total value will be updated
Here is my form
<label class="checkbox">
<input type="checkbox" class="check" value="23">SEO
</label>
<label class="checkbox">
<input type="checkbox" class="check" value="34">XYZ
</label>
<label class="checkbox">
<input type="checkbox" class="check" value="45">Logo Design
</label>
<span class="product-price" id="total" >45</span>
jQuery I have used
$('input[type=checkbox]').change(function () {
var val = parseFloat(this.value),
totalVal = parseFloat($('#total').val());
if (this.checked) {
$('#total').val((totalVal + val).toFixed(2));
} else {
$('#total').val((totalVal - val).toFixed(2));
}
});
But nothing get updated.What could be the possible Error?
Any solution please
3
Answers
Change it:
to
as
span
do not have avalue
attribute, the text you see is thetext
attribute associated with that.Span attribute doesn’t have a
val()
property buttext()
Simply do with
Array#map
function .simply add with checked values only on each time check or uncheck .no need subtraction for below method