vendredi 24 avril 2015

JQuery Checked Selector for CheckBoxes

I am having trouble selecting the checked values for a a group of checkboxes.

I am not getting any syntax errors but the boxes are not being selected.

Code below:

var checkBoxValues = [];
$("input[name='"+ checkBoxName +"']:checked").each( function() {
    console.log(this);
    checkBoxValues.push($(this).val());
});

Code selects appropriate check boxes with the following code, but retreives all checked and unchecked:

var checkBoxValues = [];
$("input[name='"+ checkBoxName +"']").each( function() {
    console.log(this);
    checkBoxValues.push($(this).val()); 
});

Note: checkBoxName is set and is the correct name.




Aucun commentaire:

Enregistrer un commentaire