Get all checked checkboxes in the datatable

Get all checked checkboxes in the datatable

Danielss89Danielss89 Posts: 2Questions: 0Answers: 0
edited August 2010 in General
Hi,
I have a table with some data, and a checkbox in each row.
Now each have a value, and when a user changes a selectbox og want the values of the checked checkboxes.

This is what i've got:

[code]$(".checkboxId").each(function(){
$("input:checked", table.fnGetNodes()).each(function(){
console.log($(this).val());
});
});[/code]

But if i just check one checkbox, the value of that checkbox is logged x times(x beeing the total number of checkboxes).

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited August 2010
    Too many 'each's I think :-). The first loop is looping over every checkbox (well almost very checkbox - it will be the visible ones) - presuming the class matches, and the second one, is picking up the one checked checkbox everytime. So how about just:

    [code]
    $("input:checked", table.fnGetNodes()).each(function(){
    console.log($(this).val());
    });
    [/code]
    Allan
  • Danielss89Danielss89 Posts: 2Questions: 0Answers: 0
    OMG.. how can i be that blind :S

    Thx :)
  • AntonioJuniorAntonioJunior Posts: 2Questions: 0Answers: 0
    Thanks for code.
  • NJDave71NJDave71 Posts: 40Questions: 3Answers: 0
    edited July 2011
    In this example

    $("input:checked", table.fnGetNodes()).each(function(){
    console.log($(this).val());
    });

    How can I return The Row ID for each item checked?
This discussion has been closed.