Last active
March 24, 2017 11:11
-
-
Save denwwer/395a194e34528fa6119d646b76c26f5c to your computer and use it in GitHub Desktop.
Handle unchecked checkboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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 +'">'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great 👍