Sum of data attributes of checkbox data-price






<html><head>
 
  <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.js"></script>

<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$(document).ready(function () {
$('.checkbox').prop('checked', false);
$('.checkbox').on("change", function () {
   
    var totalPrice = 0;

    $('.checkbox:checked').each(function () {
        totalPrice += parseInt($(this).data('price'), 10);
    });

    $('.price').html(totalPrice);
   
});
});
});//]]>

</script>
</head>
<body>
  <input class="checkbox" id="one" data-price="10" type="checkbox">one
<br>
<input class="checkbox" id="two" data-price="5" type="checkbox">two
<br>
<input class="checkbox" id="three" data-price="2" type="checkbox">three
<br>

<span class="price"></span>
 




</body></html>

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Hyperledger Development with in 10 days — Day 6

Insert CheckBox and Radio button Data in MySQL Database Using PHP