Getting the value of input[type=hidden] in a hidden column of datatable Getting the value of input[type=hidden] in a hidden column of datatable codeigniter codeigniter

Getting the value of input[type=hidden] in a hidden column of datatable


It's a little difficult to see exactly what's going wrong here. Sometimes you are referring to the hidden input having a name of "personID" in your code snippets, and sometimes "guestID". It would obviously cause issues if this disparity exists in your actual code.

If you make sure that the rendered HTML is what you expect (using personID as the hidden input's name) then the following should work:

$('#table_data tbody').on('click', 'tr', function () {    var $tr = $(this);    if ($tr.hasClass('active')) {        $tr.removeClass('active');    } else {        $tr.addClass('active');        // Use the input's name to find it within the <tr>        var d = $tr.find('input[name=personID]').val();        alert(d);    }});

Example: JSFiddle

Then, it seems overkill to have a whole table column just for a hidden input. You could simply place the hidden input in the same column as the person's name - or even store it as a data attribute on the table row itself. Also, in your PHP loop, you are giving all your hidden inputs the same "personID" ID which is not technically correct - all ID values in an HTML document should be unique.