Showing posts with label jQuery Checkbox. Show all posts
Showing posts with label jQuery Checkbox. Show all posts

Thursday, July 5, 2012

Asp.Net jQuery checkboxlist get checked items list


In this post Asp.Net jQuery checkboxlist get checked items list, we shall see on how to loop through all the checkboxes in a CheckBoxList and get the list of values checked.

We can loop through all the checkboxes in the CheckBoxList by filtering the type checkbox in as follows

    var selectedIDs = '';
    var selectedValues = '';
    $('#chkListCity input:checkbox').each(function() {
        if ($(this).attr('checked')) {
            if (selectedIDs.length == 0) {
                selectedIDs = $(this).attr('id');
                selectedValues = $('label[for=' + this.id + ']').html();
            }
            else {
                selectedIDs += ", " + $(this).attr('id');
                selectedValues += ", " + $('label[for=' + this.id + ']').html();
            }
        }
    });
    alert('Selected IDs: ' + selectedIDs);
    alert('Selected Values: ' + selectedValues);

To loop through all the checkboxes in the page on the click event of a button use the following script.

// Loop through - Get List of Selected Checkboxes in the CheckBoxList
$('#cmdGetSelectedCheckboxList').click(function(event) {
    event.preventDefault();
    var selectedIDs = '';
    var selectedValues = '';
    $('#chkListCity input:checkbox').each(function() {
        if ($(this).attr('checked')) {
            if (selectedIDs.length == 0) {
                selectedIDs = $(this).attr('id');
                selectedValues = $('label[for=' + this.id + ']').html();
            }
            else {
                selectedIDs += ", " + $(this).attr('id');
                selectedValues += ", " + $('label[for=' + this.id + ']').html();
            }
        }
    });
    alert('Selected IDs: ' + selectedIDs);
    alert('Selected Values: ' + selectedValues);
});


To see a full example using jQuery and Checkbox refer to the post Asp.Net jQuery checkbox Tutorial
.





Related Posts

Asp.Net jQuery loop through CheckBoxes in CheckBoxList


In this post Asp.Net jQuery loop through CheckBoxes in  CheckBoxList, we shall see on how to loop through all the checkboxes in a CheckBoxList and get the list of values checked.

We can loop through all the checkboxes in the CheckBoxList by filtering the type checkbox in as follows

$('#chkListCity input:checkbox').each(function() {
   alert($(this).attr('id') + ' => ' + $(this).is(':checked'));
});

To loop through all the checkboxes in the page on the click event of a button use the following script.

// Loop through all Checkboxes in a CheckBoxList
$('#cmdLoopList').click(function(event) {
    event.preventDefault();
    $('#chkListCity input:checkbox').each(function() {
        alert($(this).attr('id') + ' => ' + $(this).is(':checked'));
    });
});

Asp.Net jQuery checkbox get checked items list


In this post Asp.Net jQuery checkbox get checked items list, we shall see on how to loop through all the checkboxes in the page and get the list of values checked.

We can loop through all the checkboxes in the page by filtering the type checkbox in the page elements as follows and get the list of checked values.

    var selectedIDs = '';
    var selectedValues = '';
    $("input[type=checkbox][checked]").each(function() {
        if (selectedIDs.length == 0) {
            selectedIDs = $(this).attr('id');
            selectedValues = $('label[for=' + this.id + ']').html();
        }
        else {
            selectedIDs += ", " + $(this).attr('id');
            selectedValues += ", " + $('label[for=' + this.id + ']').html();
        }
    });
    alert('Selected IDs: ' + selectedIDs);
    alert('Selected Values: ' + selectedValues);

To loop through all the checkboxes in the page on the click event of a button use the following script.

// Loop through - Get List of Selected Checkboxes in the Page
$('#cmdGetSelectedList').click(function(event) {
    event.preventDefault();
    var selectedIDs = '';
    var selectedValues = '';
    $("input[type=checkbox][checked]").each(function() {
        if (selectedIDs.length == 0) {
            selectedIDs = $(this).attr('id');
            selectedValues = $('label[for=' + this.id + ']').html();
        }
        else {
            selectedIDs += ", " + $(this).attr('id');
            selectedValues += ", " + $('label[for=' + this.id + ']').html();
        }
    });
    alert('Selected IDs: ' + selectedIDs);
    alert('Selected Values: ' + selectedValues);
});

Asp.Net jQuery loop all checkbox values in Page


In this post Asp.Net jQuery loop all checkbox values  in Page, we shall see on how to loop through all the checked checkboxes in the page and get the values of the checkboxes using jQuery.

We can loop through all the checkboxes in the page by filtering the type checkbox in the page elements as follows and get the values.

$("input[type=checkbox]").each(function() {
alert($('label[for=' + this.id + ']').html() + ' => ' + $(this).is(':checked'));
});

To loop through all the checkboxes in the page on the click event of a button use the following script.

// Loop through - Get CheckBox Label/Values
$('#cmdGetValues').click(function(event) {
    event.preventDefault();
    $("input[type=checkbox]").each(function() {
        alert($('label[for=' + this.id + ']').html() + ' => ' + $(this).is(':checked'));
    });
});

Asp.Net jQuery loop through all checked Checkboxes in Page


In this post Asp.Net jQuery loop through all checked Checkboxes in Page, we shall see on how to loop through all the checked checkboxes in the page using jQuery.

We can loop through all the checkboxes in the page by filtering the type checkbox in the page elements as follows.

$("input[type=checkbox][checked]").each(function() {
        alert($(this).attr('id') + ' => ' + $(this).is(':checked'));
});

To loop through all the checkboxes in the page on the click event of a button use the following script.

// Loop through all Checked Checkboxes in the page
$('#cmdLoopChecked').click(function(event) {
    event.preventDefault();
    $("input[type=checkbox][checked]").each(function() {
        alert($(this).attr('id') + ' => ' + $(this).is(':checked'));
    });
});

Asp.Net jQuery loop through all Checkboxes in Page


In this post Asp.Net jQuery loop through all Checkboxes in Page, we shall see on how to loop through all the checkboxes in the page using jQuery.

We can loop through all the checkboxes in the page by filtering the type checkbox in the page elements as follows.

$("input[type=checkbox]").each(function() {
        alert($(this).attr('id') + ' => ' + $(this).is(':checked'));
    });

To loop through all the checkboxes in the page on the click event of a button use the following script.

// Loop through all Checkboxes in the page
$('#cmdLoop').click(function(event) {
    event.preventDefault();
    $("input[type=checkbox]").each(function() {
        alert($(this).attr('id') + ' => ' + $(this).is(':checked'));
    });
});

Asp.Net jQuery checkbox click event handler


In this post Asp.Net jQuery checkbox click event handler, we shall see on how to handle the clicked/checked event of a checkbox using jQuery.

We can use the click() event to track the clicked/checked events of a checkbox as follows.

// Checkboxes Checked Event
$('#chkStatus').click(function() {
    alert($('#chkStatus').attr('checked') ? true : false);
    alert($('#chkStatus:checked').val() ? true : false);
    alert($('#chkStatus:checked').is(':checked'));
});

All 3 alerts mentioned return the same result, the checked state of the checkbox, any one of it can be used.