calculating check boxes

纵然是瞬间 提交于 2019-12-22 00:30:11

问题


I am facing a problem in contact form 7, and I would like to have some help. The problem that I am having is that I have a set of Check boxes that I would like to have a total show when a client clicks on it.

MY Check box: (multiple select ) can pick more then one

  [checkbox GRCGA class:multipal use_label_element "$10.00" "$20.00" "$25.00" "$50.00" "$75.00" "$100.00" "$200.00" "$400.00" "$500.00"]


Total Amount: <span id="total">$00</span>.00

Jvascript:

$("input[type=checkbox]").change(function(){
    updateTotal();
});

function updateTotal(){
    var total = 0;
    $("input[type=checkbox]:checked").each(function(){
        total += parseFloat($(this).val());
    });
    $("#total").html(total);
}

Will this work to get the total amount when they select one or more to get the amount that they want.


回答1:


<script>
        $(document).ready(function() {
$("input[type=checkbox]").on("change", function() {
    var tot = 0;
    $("input[type=checkbox]:checked").each(function() {
       var val = this.value.substr(1).split(' ')[0];
tot += +(val);   
 });
         $("#result").text("Total: $" + tot);       
      });
        });
    </script>

Hope this will help you



来源:https://stackoverflow.com/questions/26457274/calculating-check-boxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!