Skip to content

Instantly share code, notes, and snippets.

@denwwer
denwwer / checkbox.js
Last active March 24, 2017 11:11
Handle unchecked checkboxes
$('input[type="checkbox"]').bind('change', function() {
var $checkbox = $(this);
var id = this.id + '-hidden';
if ($checkbox.is(':checked')) {
$('#' + id).detach();
} else {
var name = $checkbox.attr('name');
$checkbox.before('<input type="hidden" name="'+ name +'" value="0" id="'+ id +'">');
}