0

I would like to enable the user to select a checkbox in a table, and then display the next table cell row data.

I have created a test project

http://jsfiddle.net/tonymaloney1971/8n4c42ap/

So, in my example if you select checkbox on row 1, I would like a alert box displaying item 1.

$("input[type='checkbox']").change(function (e) {
    if ($(this).is(":checked")) {
        $(this).closest('tr').addClass("highlight_row");
        //this errors?
        var itemID = $('.record_table', this).html();
        alert(itemID);
    } else {
        $(this).closest('tr').removeClass("highlight_row");
    }
});

Thanks

3 Answers 3

2

You can check Demo

Below is updated JS code

$(document).ready(function () {
    $('.record_table tr').click(function (event) {
        if (event.target.type !== 'checkbox') {
            $(':checkbox', this).trigger('click');
        }
    });

    $("input[type='checkbox']").change(function (e) {
        if ($(this).is(":checked")) {
            $(this).closest('tr').addClass("highlight_row");
            //this errors?
            var itemID = $(this).parent('td').next('td').html();
            alert(itemID);
        } else {
            $(this).closest('tr').removeClass("highlight_row");
        }
    });
});

I think it will help you

Sign up to request clarification or add additional context in comments.

Comments

1

Try this to achieve

 var itemID = $(this).parent().next().html();
 alert(itemID);

DEMO

Comments

0

here you go: DEMO

$(document).ready(function () {
    $('.record_table tr').click(function (event) {
        if (event.target.type !== 'checkbox') {
            $(':checkbox', this).trigger('click');
        }
    });

    $("input[type='checkbox']").change(function (e) {
        if ($(this).is(":checked")) {
            $(this).closest('tr').addClass("highlight_row");
            var itemID = $(this).parent().siblings('td').html();
            alert(itemID);
        } else {
            $(this).closest('tr').removeClass("highlight_row");
        }
    });
});

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.