execv
execv

Reputation: 849

Check Checkbox On Row Click

I have the following HTML (many, many rows):

<tr>
    <td class="order_row"><input type="checkbox" name="data[Order][id][]" value="951"></td>
    <td class="order_row">04/03/2014</td>
    <td class="order_row">Test</td>
    <td class="order_row">123</td>
</tr>

Anytime I click on any TD, I want to check the checkbox in that row. I have something like this:

$('.order_row').css('cursor', 'pointer').click(function() {
    $(this).parent('tr').find('input').trigger('click');
});

But that's not working. Any help?

Upvotes: 0

Views: 2887

Answers (3)

JohanVdR
JohanVdR

Reputation: 2880

http://jsfiddle.net/fuR6u/10/

$(function(){
  $('.order_row').css('cursor', 'pointer').click(function() {
    var checkbox =  $(this).parent('tr').find('input[type=checkbox]');
    if(checkbox.length > 0 && checkbox.is(':checked')) alert('checked!');
  });
});

Upvotes: 0

Devima
Devima

Reputation: 1566

If you want toggle on of checked by clicking on td you can use this code

<script type="text/javascript">
$(document).ready(function(){
    $('.order_row').css('cursor', 'pointer').click(function() {
        var checkBoxes = $(this).parent('tr').find('input:checkbox')
        checkBoxes.prop("checked", !checkBoxes.prop("checked"));
    });
})
</script>

Upvotes: 1

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

Here is the code for it:

$(document).ready(function(){

$('table').on('click','.order_row',function() {

    $(this).parent('tr').find('input').prop("checked",true);

     });


});

Working Fiddle DEMO

Upvotes: 0

Related Questions