Amanada Smith
Amanada Smith

Reputation: 1981

Getting Specific checkboxes

I need to get my series of checked checkboxes without getting all the rest on the page so I'm trying to narrow down specifically but the following code does not seem to work.

$('#button').click(cc);
    function cc() {
        var va = [];
          $('input:checkbox[name=lpids]:checked').each(function(i){
            va.push(this.id);
          });
        alert(va);
    }

and

<asp:CheckBox ID="ck0" runat="server" name="lpids" ClientIDMode="Static"/>

Now I looked on up getting specific values and the above should work but I'm getting nothing.

EDIT:

<span name="lpids" class="chk"><input id="ck6" type="checkbox" name="ctl00$ck6" /></span>

What I'm getting in source code.

Upvotes: 0

Views: 92

Answers (4)

Musa
Musa

Reputation: 97727

From what is generated, this should work

$('[name=lpids] [type=checkbox]:checked').each(function(i){

Upvotes: 1

Rob
Rob

Reputation: 1216

try this fiddle I just created and it pulls the id. just add class="chk" to each checkbox...

http://jsfiddle.net/eformx/xENNa/

The guts...

$('#button').click(function () {

    $('.chk').each(function() {

        var checked = this.checked ? 'checked' : '';
        if (checked){
            var id = this.id;
            alert(id);
        }
    });


});

Upvotes: 0

David Cheung
David Cheung

Reputation: 858

Try this:

$('#button').click(cc);
    function cc() {
          $('input[name=lpids]:checked').each(function(){
            alert($(this).attr('id'));
          });
    }

Upvotes: 0

Justin
Justin

Reputation: 1949

Instead of

this.id

try

$(this).attr('id')

Upvotes: 0

Related Questions