views:

37

answers:

3

I have a table that has checkboxes within tds. The checkboxes have ids that form an array (s[1], s[2], s[3], s[4], etc...) and I am trying to find out the numeric row location of the checkbox within the table>tbody (YES, this row location also matches the index inside the array. Here's the code I'm trying but the result is always "0":

    $('input:checkbox').bind('change',function() {
        var thisRow = $('tbody tr').index();
        $('input:text[id=qty[' + thisRow + ']').attr('readonly','false')
        .focus();
        alert(thisRow);
    });
A: 

How about:

$('input:checkbox').bind('change',function() {
    var thisRowindex = $(this).closest("tr")[0].rowIndex;
    ...

Demo: http://jsfiddle.net/DEEKy/2/

karim79
Many thanks, karim.
DevlshOne
A: 

$(this).closest('tr').index() should also work

Ionut Staicu
A: 

From a combination of all these excellent answers, I have come up with this:

    $('input:checkbox').bind('change',function() {
        $(this).closest('input:text[id^=qty]').removeAttr('readonly').focus();
    });

But, it's still not allowing input to nor focusing on the box that's at the end of the same row in the table. Any thoughts?

DevlshOne