Good day,
I'm trying to remove the cookie when submitting the form, but its not working.
Here is my code:
$("form").submit(function()
{
var cookiePath = "Table_Rows-"+$(location).attr('pathname');
alert(cookiePath);
$.removeCookie(cookiePath);
}
Even if I delete all cookies using these code, it still won't work:
$("form").submit(function()
{
for (var it in $.cookie()) $.removeCookie(it);
}
Im setting my data to be save on a cookie via onbeforeuload function
window.onbeforeunload = function(event)
{
storeRowData();
console.log("cookie saved!");
};
and here's my StoreData() js
var storeRowData = function () {
var data = [];
$('#tblItemList tbody>tr').each(function () {
var $this = $(this),
pId = $this.find("#itemId").val();
pname = $this.find('input.itemSearch').attr("value"),
desc = $this.find(".description").val(),
quant = $this.find(".qty").val(),
rowId = $this.find(".rowId").val(),
deleted = $this.find(".hidden-deleted-id").val(),
price = $this.find(".price").val();
var temp = {
productName: pname,
itemId:pId,
description: desc,
quantity: quant,
price: price,
deleted:deleted,
rowId: rowId };
data.push(temp);
});
var cookiePath = 'Table_Rows-'+$(location).attr('pathname');
$.cookie(cookiePath, JSON.stringify(data), {expires: 7});
}
then im checking if cookie was set on the page on document.ready function:
if($.cookie('Table_Rows-'+$(location).attr('pathname'))){
loadCookieData();
$(".qty, .price").bind("keyup change", calculate);
}
else{
addRow(0);
}
and my loadCookieData()
var cookiePath = 'Table_Rows-'+$(location).attr('pathname');
//console.log("loadCookieData:"+cookiePath);
temp = $.cookie(cookiePath);
var parseData = JSON.parse(temp);
//console.log(parseData);
var html ='';
for (i in parseData) {
subTotal = parseData[i].quantity*parseData[i].price;
var st = new Number(subTotal);
var sub = st.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
html+= (some html code to replace here)
}
$("#tblItemList tbody").html(html);
for (i in parseData){
var inputBox = "#itemName"+parseData[i].rowId;
$(inputBox).select2(sOptions);
}
calculate();
}
Is there something wrong with my current code ??
Can anyone tell me how to properly do it please? Thank you very much!