I am trying to create a clipboard box where I can copy some columns from a table on the parent page/window to a pop up window.
Parent window elements:
- Table with checkbox per row (selection)
- Button to copy rows to another window table
Popup window elements:
- Table which has no row (tbody only)
FILE 1: JavaScript file of Parent Window
$("#button_copy").on("click", function() {
var l_url = "<?php echo base_url(); ?>clipboard/";
var l_name = "ClipboardWindow";
var l_height = 500;
var l_width = 1000;
var l_params = 'status=1' +
',resizable=1' +
',scrollbars=1' +
',width=' + l_width +
',height=' + l_height +
',left=0' +
',top=0';
// get selected rows details
var table_result = $("#table_result");
var row_contents = [];
$('input:checkbox:checked', table_result).map(function() {
var row = [];
row['item_code'] = $(this).closest('tr').find('.row_item_code').text();
row['sales_description'] = $(this).closest('tr').find('.row_sales_description').text();
row['buy_description'] = $(this).closest('tr').find('.row_buy_description').text();
row['sell'] = $(this).closest('tr').find('.row_sell').text();
row['buy'] = $(this).closest('tr').find('.row_buy').text();
row_contents.push(row);
});
// display selected rows on the pop up window
var row_html = "";
row_contents.forEach(function(row) {
row_html = row_html + "<td>" + row['item_code'] + "</td>";
row_html = row_html + "<td>" + row['sales_description'] + "</td>";
row_html = row_html + "<td>" + row['buy_description'] + "</td>";
row_html = row_html + "<td>" + row['sell'] + "</td>";
row_html = row_html + "<td>" + row['buy'] + "</td>";
});
if ((myWindow == null) || (myWindow.closed)) {
console.log("new window");
// open pop up window and get document for processing
myWindow = window.open(l_url, l_name, l_params);
myWindow.document.getElementById("tbody_result").append("<tr>" + row_html + "</tr>");
} else {
console.log("existing window");
myWindow.document.getElementById("tbody_result").append("<tr>" + row_html + "</tr>");
}
});
FILE 2: HTML File of Popup Window:
<div class="panel-body">
<table width="100%" class="table table-striped table-bordered table-hover" id="table_clipboard">
<thead>
<tr>
<th>Item Code</th>
<th>Sales Description</th>
<th>Buy Description</th>
<th>Sell</th>
<th>Buy</th>
</tr>
</thead>
<tbody id="tbody_result">
</tbody>
</table>
<!-- /.table-responsive -->
</div>
I am not able to make it work.. Here are my problems:
- The row is not created upon window.open
- It has error initial:
TypeError: Cannot read property 'append' of nullwhich maybe the dom has not yet been loaded since call? - The JS appends new row but only after the page was loaded by previous button click (which is okay)
- The JS appends only add 1 row and 1 column which is not in HTML format but text (image attached below)

<tr>, not all html inside one table row.appendfunction on a HTMLElement. You're probably looking forappendChild, but that doesn't take HTML text. I think you want to do$('#tbody_result', myWindow.document)instead.append("<tr>" + row_html + "</tr>");I will modify this one.. Thank you