Q:

Checkbox event and holding array - how to handle in code?

I have the following code in my phonegap app:
 function onDeviceReady() {
            var listOfSports = new Array(["Aikido"],["Air Sports"],["American Football"],["Angling"],["Archery"],["Yoga"]);
            $.each(listOfSports, function (i) {
                console.log(i);
                var li = $('<li><input class="checkbox" type="checkbox"' + 'id="' + listOfSports[i] + '"' + 'label="' + listOfSports[i] + '">' + listOfSports[i] + '</li>')
                    .appendTo("ul.listViewContainer");
            });
            $("#listViewContainer").listview();
            $("#listViewContainer").listview("refresh");
        }

How can I get the value of checked items and add the value to an array when checked or remove when unchecked?

A:

Something like this. This will store all the checkbox ID in an array.
var arr = [];

function onDeviceReady() {
        var listOfSports = new Array(["Aikido"],["Air Sports"],["American Football"],["Angling"],["Archery"],["Yoga"]);
        $.each(listOfSports, function (i) {
            console.log(i);
            var li = $('<li><input class="checkbox" type="checkbox"' + 'id="' + listOfSports[i] + '"' + 'label="' + listOfSports[i] + '">' + listOfSports[i] + '</li>')
                .appendTo("ul.listViewContainer");
        });
        $("#listViewContainer").listview();
        $("#listViewContainer").listview("refresh");

        $(".checkbox").click(function () {
            if ($(this)[0].checked)
            {
                arr.push($(this).attr("id"));
            }
            else
            {
                arr = $.grep(arr, function( a ) {  
                           return a != $(this).attr("id");
                      });
            }
        });
    }

Edit :
Just a little mistake. Here a fiddle : http://jsfiddle.net/wyfr8/207/
        else
        {
            var check = $(this);
            arr = $.grep(arr, function( a ) { 
                       return a != $(check).attr("id");
                  });
        }

