Advertisement
techouse

Untitled

Mar 20th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {
  2.     var hashArray = {};
  3.     $('.myCheckbox').on('change', function() {
  4.         var self = $(this),
  5.             checkboxId = parseInt(self.attr('data-id')), // since you used it as a number above
  6.             checkboxValue = parseInt(self.val()); // since you also used it as a number above
  7.         if (self.is(':checked')) {
  8.             // add to array
  9.             if (!hashArray.hasOwnProperty(checkboxId)) hashArray[checkboxId] = [];
  10.             hashArray[checkboxId].push(checkboxValue);
  11.         }
  12.         else {
  13.             if (hashArray.hasOwnProperty(checkboxId)) {
  14.                 // remove from array if it exists
  15.                 hashArray[checkboxId].splice(hashArray[checkboxId].indexOf(checkboxValue), 1);
  16.             }
  17.         }
  18.     });
  19. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement