Skip to content

Instantly share code, notes, and snippets.

@denwwer
Last active March 24, 2017 11:11
Show Gist options
  • Save denwwer/395a194e34528fa6119d646b76c26f5c to your computer and use it in GitHub Desktop.
Save denwwer/395a194e34528fa6119d646b76c26f5c to your computer and use it in GitHub Desktop.
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 +'">');
}
});
@Vitaleks-project
Copy link

Great 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment