Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div class="invoice">
    <input type="checkbox" checked='checked' value="1" />
        <span class="inv-total">$100</span>
</div>
<input type="text" class="total" value="$90" />
</body>
</html>
 
$(function() {
     $defaultValue = $('.total').val().replace('$','');
    $("input[type=checkbox]").click(function(event) {
        var total = 0;
        $("input:checked").each(function() {
            total += parseInt($(this).parent().find('.inv-total').text().substring(1));
        });
        if (total == 0) {
            $('.total').val($defaultValue);
        } else {
            $('.total').val(total);
        }
    });
})
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers