Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2011, 09:35 AM   PM User | #1
wolfenr
New Coder

 
Join Date: Oct 2011
Posts: 43
Thanks: 18
Thanked 1 Time in 1 Post
wolfenr is an unknown quantity at this point
Cookies for shopping cart

Hi and hope someone can help,

I'm doing some course work on setting / getting cookies for a shopping cart. It basically works except the user can only select one item of each of the goods on offer i.e. you can only buy one cup (not two), one saucer etc. etc.

I've deliberately not put a quantity field on the goods selection page and was hoping to modify my set cookie function so that if you've already selected one cup, the next tiume you select a cup, cups become 2 etc. etc.

Here's my set cookie function. Notice that I've hard wired a "1" in there which I want to change to the variable for the number of cups. I've also commented out some of the first few lines which were experiments to resolve the problem.

Code:
  function setCookie(name)
  {
	  alert("Thank you.\n\nYour basket has been updated.");
/*	if(name.value !=0 || name.value==null)
	name.value++;
	x=getCookie(name) || 0;
	alert(document.cookie);*/

	  var today = new Date();
	  var expiry = new Date(today.getTime()+28*24*60*60*1000); // plus 28 days
	  document.cookie=name+"=1;expires="+expiry.toGMTString();
	  cart = document.cookie;
  }
My thanks,
R

A little while later...
I've cracked it, my function now looks like this and it appears to work...

Code:
function setCookie(name)
{
	  alert("Thank you.\n\nYour basket has been updated.");
	  x=parseInt(getCookie(name)) || 0;
	  alert(x);
	  y=x+1;
	  var today = new Date();
	  var expiry = new Date(today.getTime()+28*24*60*60*1000); // plus 28 days
	  document.cookie=name+"="+y+";expires="+expiry.toGMTString();
	  cart = document.cookie;
	  }
Thanks you fror your interest, appreciated,
R

Last edited by wolfenr; 10-27-2011 at 09:49 AM.. Reason: Resolved
wolfenr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:17 AM.


Advertisement
Log in to turn off these ads.