i have bit of code carries numeric values within span when u click on checkbox subtract 1 main value, subtracts 1 total value, how achieve if form submitted deducted value in span remains same unless checkbox unchecked?
html here 10 example value:
<input type="checkbox" id="featured" name="featured" <?php echo $checked;?> /> (<span id="credit">10</span>)
js:
<script> $(function () { $('#featured').change(function () { var currentvalue = parseint($('#credit').text()); var newvalue = currentvalue + ($(this).prop('checked') ? -1 : 1); $('#credit').text(newvalue); }); }); </script>
your time , appreciated.
<script> $(function () { $('#featured').change(function () { var savedvalue = localstorage.checkboxvalue; var currentvalue = savedvalue ? parseint(savedvalue) : parseint($('#credit').text()); var newvalue = currentvalue + ($(this).prop('checked') ? -1 : 1); $('#credit').text(newvalue); localstorage.checkboxvalue = newvalue; }); }); </script>
Comments
Post a Comment