Manish Tiwari Manish Tiwari - 4 months ago 18x
jQuery Question

How to make key value pair array when chekbox checked using jquery?

I have multiple checkbox, when i check a checkbox two key value pair will generate.

Like this :

Object {id: "101", name: "example"}

This will generate for every checkbox checked and i want for multiple checkbox checked array. look like this :


What I have done

$('.chkCompare').click(function(event) {
var value = [],
projectName = {},
span = $(this).attr('id'),
value = $('.chkCompare:checked').map(function() {
$('#span' + span).text('ADDED').css({
"color": "green"
projectName['id'] = $(this).attr('id');
projectName['name'] = $(this).attr('title');
return value.push(projectName);

When I uncheck checkbox they will be remove from array and want to prevent check maximum 3 checkbox
if >3
then show an alert box.

      var arr = {};
       var count = 0;
      $.each($("input[type='checkbox']:checked"), function(){            
           $(this).prop('checked', false);