user1173169
user1173169

Reputation:

Select only checked boxes with Jquery Selector

With the following block of code :

function DownloadZip()
{
$('.DownloadZip').click(function(){

var str = "";
$("#table_csrdownloadcenter tr").each(function() {
    str += $("td:eq(7) input[type=checkbox]:checked", this).attr("name");
})

console.log(str);
});
}

i try to save in a string the "name" attributes of every checked boxes. My problem is this block of code saves in "str" the string "undefined" when the box is not checked. I don't want it to save anything if the box is not checked.

Can you help me to achieve this ? thanks

PS: for information, this is how my table looks like:

<table summary='' id='table_csrdownloadcenter'>
<thead>
<tr>
<th>text1</th>
<th>text2</th>      
<th>text3</th>
<th>text4</th>
<th>text5</th>
<th>text6</th>
<th>text7</th>
<th>text8</th>
</tr>
</thead>
<tbody> 

<tr id='nom_du_pdf'>
<td class='dc-date'></td>
<td class='dc-dl'></td>                                             
<td class='dc-title'></td>
<td class='dc-area'></td>
<td class='dc-category'></td>
<td class='dc-file'></td>
<td class='dc-ranking'></td>
<td class='dc-checkbox'><input type='checkbox' name='chk"+PathFile[i]+"' ></td>
</tr>

<tr id='nom_du_pdf2'>
<td class='dc-date'></td>
<td class='dc-dl'></td>                                             
<td class='dc-title'></td>
<td class='dc-area'></td>
<td class='dc-category'></td>
<td class='dc-file'></td>
<td class='dc-ranking'></td>
<td class='dc-checkbox'><input type='checkbox' name='chk"+PathFile[i]+"' ></td>
</tr>


</tbody>
<table>

Upvotes: 0

Views: 81

Answers (2)

Pramod
Pramod

Reputation: 141

Try

$("#table_csrdownloadcenter td.dc-checkbox input[type=checkbox]:checked").each(function()       {
    str += $(this).attr("name");
})

Upvotes: 1

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try,

$("#table_csrdownloadcenter tr td:nth-child(8) input[type=checkbox]:checked").each(function() {
    str += $(this).attr("name");
})

Upvotes: 0

Related Questions