.

working with JQuery checkboxes – append to array

checking if a checkbox is checked and append it’s data value to an array:

 $(':checkbox').each(function () {
    var allPEtasks = new Array();
    var count = 0;
    var cb = $(this);
    if (cb.attr('checked'))  {
        var TaskId = cb.data('taskid');
        if (TaskId != null) {
                allPEtasks[count] = TaskId;
                count++;
            }
    }
});

this could be the razor view generating the html:

    foreach (var @tt in Model)
    {
        if ((tt.Task_commence_date != null) && (tt.Task_completed_date == null))
        {
            <div  class="TrafficLight_@(((TaskResultCode) @tt.TaskResultCode).ToString())" >@tt.Task_description 
            <input type="checkbox" data-petaskid="@tt.Patient_episode_task_id" />
            </div>
        }
    }