checkbox value 0 or 1
Just to be a butt and offer a slightly shorter answer:
$('input[type="checkbox"]').change(function(){
this.value = (Number(this.checked));
});
Thanks worked as in
$('#custom7').on('change', function(){
this.value = this.checked ? 1 : 0;
// alert(this.value);
}).change();
link: http://jsfiddle.net/WhQaR/
Don't forget about the bitwise XOR
operator:
$('input[type="checkbox"]').on('change', function(){
this.value ^= 1;
});
$('input[type="checkbox"]').on('change', function(){
this.value ^= 1;
console.log( this.value )
});
<label><input type="checkbox" name="accept" value="1" checked> I accept </label>
<label><input type="checkbox" name="accept" value="0"> Unchecked example</label>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>