Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($) {
- var hashArray = {};
- $('.myCheckbox').on('change', function() {
- var self = $(this),
- checkboxId = parseInt(self.attr('data-id')), // since you used it as a number above
- checkboxValue = parseInt(self.val()); // since you also used it as a number above
- if (self.is(':checked')) {
- // add to array
- if (!hashArray.hasOwnProperty(checkboxId)) hashArray[checkboxId] = [];
- hashArray[checkboxId].push(checkboxValue);
- }
- else {
- if (hashArray.hasOwnProperty(checkboxId)) {
- // remove from array if it exists
- hashArray[checkboxId].splice(hashArray[checkboxId].indexOf(checkboxValue), 1);
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement