JSFiddle - React, Tailwind, and code Playground

HTML

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/dot-luv/jquery-ui.css">
<input type="checkbox" id="c_i1" />

<input type="checkbox" id="c_i2" />

<input type="checkbox" id="c_i3" />

<input type="hidden" id="chk_count" />

JavaScript

$('input:checkbox').click(function() {

    var theID = $(this).attr('id').replace( 'c_i', '' );  // Grab the ID of the checkbox

    var $hidden = $('#chk_count');
    
    if(!$hidden.val()) {        // Increment the hidden field
        $hidden.val(theID);
    } else {
        $hidden.val( parseInt($hidden.val()) + parseInt(theID) );
    }
    
    alert('theID: ' + theID + '\n\nthe count: ' + $hidden.val());
});