If i understood correctly, you want to access the value of ID which can be used as a parameter for DB query. You can learn more about my implementation in jQuery with this link CreateEvent
You have mentioned that, on button click, you are getting the 'ID' of the selected row
"..it has a button where it would get the ID of the selected row in the first query"
And you want this ID to be appended as
SELECT * FROM marriage WHERE marriage_id = ID
as a DB query to some server, then Add below line of codes in the event listener of button click:
//event listener for button clicked
$('#btn').on('click', function(e){
//var id;
//Your logic to get the ID of the selected row and assign it to variable id
var e = $.Event( "build" );
//Trigger the custom event along with the id as data to be passed
$(this).trigger(e,[id] );
});
Now only thing left for you is to add a listener for the custom event generated, i.e. 'build'. Add that listener to the table (assuming its id-- 'tbl') and follow this:
$('#tbl').on('build', function(e, param){
//param is the ID of the selected row. In here you can perform XHR providing ID as parameter
//alert(param);
});
Hope that helps to resolve the problem you are facing now!