calculating check boxes

2019-04-17 06:25发布

问题:

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