1

I need small suggestion from you.

Onclick of the checkbox attribute inside that should be changed.There is also a inside the

HTML Code:

 <table>
 <tr>
 <td class="answer"><input tabindex="4" type="checkbox" name="Dum1_4" id="Dum1_4" value="1"/></td>
 <td class="answerlabel"><label for="Dum1_4" id="Dum1_4_label"><table class="sample"><tr><td><img src="/ThumbsV2/2200000999-f.png"></td></tr><tr><td><b>Product 4</b></td></tr><tr><td>Product Description 4</td></tr><tr><td><b>Price 4</b></td></tr></table></label></td>
</tr>
<tr>
<td class="answer"><input tabindex="5" type="checkbox" name="Dum1_5" id="Dum1_5" value="1"/></td>
<td class="answerlabel"><label for="Dum1_5" id="Dum1_5_label"><table class="sample"><tr><td><img src="/ThumbsV2/2200001080-f.png"></td></tr><tr><td><b>Product 5</b></td></tr><tr><td>Product Description 5</td></tr><tr><td><b>Price 5</b></td></tr></table></label></td>
</tr>
</table> 

Here is my code:

$('.sample').click(function()
{       
row =$this.parents("td");
row.siblings().find("input:checkbox").attr("checked","checked" );
}
});
});

Please someone help me!

Reddy
  • 1,327
  • 3
  • 23
  • 44
  • From jQuery 1.6 use "prop()" for boolean attributes. See [jQuery docs](http://api.jquery.com/prop/) for more information. `$(this).find('input:checkbox').prop('checked', true);` – Melvin Jun 10 '11 at 13:43
  • I have tried below code $(document).ready(function() { $('TABLE TBODY TR TD TABLE').click(function() { $(this).parents('td').prev('td').find('input:checkbox').attr("checked",false ); } } – Reddy Jun 10 '11 at 14:11

7 Answers7

1

try

$('TABLE TBODY TR').click(function()
{
    $(this).find('input:checkbox').attr("checked", "checked");
});

There's a decent SO thread about manipulating checkboxes with jQuery

View example here

Community
  • 1
  • 1
dotty
  • 40,405
  • 66
  • 150
  • 195
1
$('TABLE > TBODY > TR').click(function()
{
    $('input:checkbox', $(this)).prop("checked", "checked");
});
Chris
  • 7,229
  • 7
  • 41
  • 57
1

If you are trying to toggle the selected state, use the following:

jQuery 1.6+

$('table tbody tr').click(function() {
    $('input:checkbox', this).prop('checked', function(index, oldValue) {
        return !oldValue;
    });
});

jQuery pre-1.6

$('table tbody tr').toggle(function() {
    $('input:checkbox', this).attr('checked', 'checked');
}, function() {
    $('input:checkbox', this).removeAttr('checked');
});
Melvin
  • 547
  • 2
  • 10
0

this was working fine for me:

$('#checkall').click(function() {
$('#cause').children().each(function() {    
                        $(this).find("input[type='checkbox']").prop("checked", $('#checkall').prop("checked"));
                    });
                });

just use it without the each function / check / uncheck all elements

mboeckle
  • 938
  • 13
  • 29
0

Changing the value of the attribute to "checked" should work.

$('TABLE TBODY TR').click(function()
{
    $(this).find('input:checkbox').attr("checked", "checked");
});

See it in action.

Jon
  • 428,835
  • 81
  • 738
  • 806
0

try this

$(this).find('input:checkbox').attr("checked","checked"); 
Vivek
  • 10,978
  • 14
  • 48
  • 66
0

With jQuery 1.6, the code is more readable:

$("table tbody tr").click(function(){
    $(this).find("input[type='checkbox']").prop("checked",true);
});
imsky
  • 3,239
  • 17
  • 16