Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reading cookie for cart

Status
Not open for further replies.

Neomalfoy

Programmer
Jan 2, 2004
14
0
0
US
I've tried to figure this out for the past few days and I need other eyes looking at it besides me because I can't locate where I am going wrong with this script. [I can't use sessions, this has to be done with cookies.]

The script creates the cookies when items are added to an items array, then updates the items array and the cookies when the cart is updated. The form that shows the cart contents is created based on the values in the cookies. I know the cookies are being created and have not expired (I can see them in the temporary internet files for IE and in the list of cookies in FireFox) but if I refresh the page, or go to another page the cart goes back to blank. I'm pretty sure the problem has to be in the displaycart function but none of my attempts to fix it have been successful.
 
It's probably because "numitems" is 0 when the page is reloaded, and so the 'displaycart' function isn't even getting into the first loop.

Perhaps you need to store this value and read it back first?

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
P.S. I found this within seconds using The Firebug debugger for Firefox. I can highly recommend you use it for debugging JS, as it is very good, and lets you step through a line at a time, watch variables, etc.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks for the suggestion about "numitems" and firebug. I installed firebug.

I've got the script working and doing exactly what I want it to do. I'm storing "numitems" into a cookie in my additems and updatecart functions then checking the status of the "numitems" cookie to repopulate the items array if necessary.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top