I do shipping purchase. when user add to cart but not submit yet than user click to other page, I want store items in session.This is my code
var tab=document.getElementById("shippingCartForm");
var tbody = tab.getElementsByTagName( "tbody" )[ 0 ];
var row1 = tbody.getElementsByTagName( "tr" )[ 0 ];
var clnNode=row1.cloneNode(true);
sessionStorage.setItem("name", clnNode);
that is my html
<table id="shippingCartForm" border="1">
<thead>
<th>No</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Remove From Cart</th>
</thead>
<tbody>
</tbody>
</table>
So when user click to other page or refresh page. I need chack session if it's has, it's should be show talbe shippingCartForm
when user back to page purchase.
This is my script
window.onload = function() {
if (sessionStorage.getItem("name")!= null){
var tableRef = document.getElementById('shippingCartForm');
var newRow = tableRef.getElementsByTagName( "tbody" )[ 0 ];
tableRef.appendChild(sessionStorage.getItem("name"));
}
}
but I get message errors on console like this
[object HTMLTableRowElement] script.js (line 2)
TypeError: Argument 1 of Node.appendChild is not an object.
tableRef.appendChild(sessionStorage.getItem("name"));
please help me to resole it. thank for any idea.
** JavaScript only no Jquery