jQuery: Get value of checked checkboxes by name | className

Think this one speaks for itself :)

    //Get via name attribute.  Would be better if you added form ID to selector

    var checkBoxes = $("input[name=" + checkBoxName + "]");
        //Need to use each or you'll only get the first match

    $.each(checkBoxes, function() {
                if ($(this).attr('checked')){
            //do stuff
        }

        });

    //Get via class name. Would be better if you added form ID to selector

    var checkBoxes = $('.' + checkBoxClass);
        $.each(checkBoxes, function() {
            if ($(this).attr('checked')){
            //do stuff
        }
        });

Print | posted @ Wednesday, February 03, 2010 11:50 AM

Comments on this entry:

No comments posted yet.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 
Twitter