Hi All,
I am trying to create a Shopping cart in Javascript with Cookies.I am not getting an idea as to how to remove something from the cart.Here is my code.
<HTML>
<HEAD>
<TITLE>Untitled Page</TITLE>
<META http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<script language=”javascript”>
var item_productid=new Array();
item_productid[0]=”E012″
item_productid[1]=”E013″
item_productid[2]=”E014″
var item_productdesc=new Array();
item_productdesc[0]=”22karat kundan Earrings”
item_productdesc[1]=”22karat gold earrings with Enamel”
item_productdesc[2]=”22karat gold Earrings”
var item_productprice=new Array();
item_productprice[0]=”500″
item_productprice[1]=”750″
item_productprice[2]=”135″
var item_number = new Array();
if (document.cookie && document.cookie != “”)
{
process_cookie()
}
function kill_cookies()
{
var kill_date = new Date(“January 1, 1970”);
document.cookie = “jewels=stub;expires=” + kill_date.toGMTString();
}//ends kill_cookie() function
function remove(t)
{
alert(t)
//var l=k.split(“=”)
//var r=l[1].split(“xxx”)
//alert(r)
//r.splice(p,2)
//m=””
//for(i=0;i<r.length-1;i++)
//{
//m=m+r[i]+”xxx”;
//}
//document.cookie=”jewels=”+escape(m)
//alert(document.cookie)
//window.location = “viewcart.html”;
}//ends re
function process_cookie()
{
var q =new Array();
var whole_cookie = unescape(document.cookie);
var drop_name = whole_cookie.split(“=”);
if (drop_name[1] != “”)
{
item_number = drop_name[1].split(“xxx”);
}
if (item_number.length < 1)
{
document.write(“<h4>You don’t have anything ordered.</h4>”);
}//ends IF
else
{
for(i=0;i<item_number.length-1;i++)
{
if(i%2!=0)
{
q[i-1]=item_number[i];
}
}
document.write(“<table border=1><th>Quantity<th>Productid<th>ProductDesc<th>productPrice”)
var count=0;
for(i=0;i<item_number.length-1;i++)
{
if(i%2!=0)
continue;
document.writeln(“<tr><td><input type=text size=2 value=”+ q[i])
document.writeln(“<td>”+item_productid[item_number[i]])
document.write(“<td>”+item_productdesc[item_number[i]]);
document.write(“<td>”+item_productprice[item_number[i]]);
for(j=0;j<item_number.length;j++)
{
document.write(“<td><a href=’ ‘>Update</a> <a onclick=’remove(j);return false;’ href=’ ‘>Remove</a>”)
}
}
}
}//ends main display ELSE
</script>
</head>
<html>
The main problem when i remove soething is i am not able to pass values to the function remove.any help will be appreciated.
Kala