簡體   English   中英

計算總和並在文本框中顯示總金額,並在 jquery 中顯示文本“/-+GST”

[英]Calculate the sum and display in textbox to total amount and with text "/-+GST" in jquery

我正在嘗試計算所選復選框的數量並在文本框中顯示總數,並將前綴“/-+GST”添加到總量中。正在計算金額,我如何將“+GST”文本添加到金額中..

這是代碼

<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>
            
       

這樣的事情應該有效:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM