[英]Calculate the sum and display in textbox to total amount and with text "/-+GST" in jquery
I am trying to calculate the amount of the checkbox selected and display the total in textbox and also add prefix "/-+GST" to the total amount.. Amount is getting calculated and how can i add "+GST" text to the amount..我正在尝试计算所选复选框的数量并在文本框中显示总数,并将前缀“/-+GST”添加到总量中。正在计算金额,我如何将“+GST”文本添加到金额中..
Here is the code这是代码
<script>
function calcAndShowTotal() {
var total = 0;
$('#catlist :checkbox:checked').each(function() {
total += parseFloat($(this).attr('price')) || 0;
});
$('#total').val(total);
}
$('#catlist :checkbox').change(calcAndShowTotal).change();
<div id="catlist">
<input type="checkbox" name="attending[]" value="Pre-Conference" class="coupon_question" id="attend_1" price="5000+GST " required /> Pre-Conference
<input type="checkbox" name="attending[]" value="Conference" id="attend_3" price="8000+GST" required /> Conference
</div>
<label class="required-field" for="message"><b>Registration Amount</b><span style="color:red">*</span></label>
<input type="text" class="form-control" name="regamt" id= "total" placeholder="Registration Amount" style="border-radius:25px;" required>
Something like this should work:这样的事情应该有效:
var total = 0;
function calcAndShowTotal(event) {
let value = parseFloat(event.target.getAttribute('price').split("+")[0]) || 0;
if (event.target.checked) {
total += value;
} else {
total -= value;
}
$('#total').val("" + total + "+GST");
};
$('#catlist').click(calcAndShowTotal);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.