Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <input class="cbox" type="checkbox" value=".5"> .50
  <input class="cbox" type="checkbox" value="1.5"> 1.50
  <input class="cbox" type="checkbox" value="1.75"> 1.75
 
  <p>Total: <input id="total" type="text" name="total" />
</body>
</html>
 
var sum = 0;
var total = $('#total');
var cbox = $('.cbox');
$('.cbox').on('change', function() {
  if ($(this).prop('checked')) {
    sum += parseFloat($(this).val());
    updateTotal();
  } else {
    sum -= parseFloat($(this).val());
    updateTotal();
  }
});
function updateTotal() {
  total.val(sum);
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers