0

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?

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

this works but if the checkbox is in one of those td's and you click it then it cancels itself out.. a fast solution is to not give the class name to that td with the checkbox / radio button
0

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

Comments

0

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!');
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.