/    Sign up×
Community /Pin to ProfileBookmark

problem with remove in a shopping cart

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>&nbsp;<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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mdouetMar 11.2005 — I don't see where you have remove() defined.

EDIT:

NVM, I see it now.

You need to update that line of code as follows:

[CODE]
document.write("<td><a href=' '>Update</a> <a onclick='remove(" + j + ");return false;' href=' '>Remove</a>")
[/CODE]


Otherwise you will just be passing the literal 'j' to remove() instead of the value of j.
×

Success!

Help @kalak spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...