javascript - Subtract 1 from total if check box is checked -


say have checkbox , beside show numbers, 10 , when user clicks on checkbox 10 becomes 9 if unchecks again becomes 10.

<input type="checkbox" id="credits" name="credits" <?php echo $checked;?> /> (10) credit 

the value of credit fetched database.

$(function () {    $('#credits').change(function () {      var currentvalue = parseint($('#credit-amount').text());      var newvalue = currentvalue + ($(this).prop('checked') ? -1 : 1);      $('#credit-amount').text(newvalue);    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="checkbox" id="credits" name="credits" /> (<span id="credit-amount">10</span>) credit


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -