Am trying to implement a shopping cart in java script which is using cookies.
I have a form consisting of itemID,quantity and price. these are details that the user has selected.
below is the code with two functions setcookie called from a button click event and getcookie called from link click event.But nothing is happening.Could anyone help me to figue what is the problem with the code.the others are comments after i discovered its not working,i was trying others. - <script language="JavaScript">
-
//global variables;
-
var itemarray = new array
-
itemarray[0]=itemid
-
itemarray[1]=quantity
-
itemarray[2]=price
-
-
function setcookie(ccookie,itemarray);
-
{
-
document.cookie= ccookie + "=" + escape(itemarray);
-
var scookie =ccookie;
-
var itemID = new string(itemarray[0]);
-
//document.cookie=scookie;
-
var start= scookie.indexof(itemid + "&");
-
If start>==0 {
-
var end =scookie.indexof("£",start+1)+1;
-
if (itemarray[1] >0) {
-
-
sCookie = sCookie.replace(sCookie.slice(Start,End), itemID + “&” + itemarray[1] + "& "itemarray[2] "£");
-
-
}
-
else {
-
-
//new item quantity is 0 so remove it from basket
-
-
-
sCookie = sCookie.replace (sCookie.slice(Start,End), “”);
-
-
}
-
-
}
-
-
else {
-
-
//item not in basket already
-
-
sCookie = sCookie.concat(itemID + “&”, itemarray[1] + "&: itemarray[2] “£”);
-
-
}
-
-
return sCookie;
-
-
}
-
-
Functio getcookie(scookie)
-
{
-
//var rcookie = document.cookie;
-
if (document.cookie.length>0)
-
{
-
c_start=document.cookie.indexOf(scookie + "=")
-
if (c_start!=-1)
-
{
-
c_start=c_start + scookie.length+1
-
c_end=document.cookie.indexOf(";",c_start)
-
if (c_end==-1) c_end=document.cookie.length
-
return unescape(document.cookie.substring(c_start,c_end))
-
}
-
}
-
return ""
-
-
//var start = rcookie.indexof(itemid + "&");
-
//var end =rcookie.indexof("&",start+1);
-
//var citem =rcookie.slice(start,--end);
-
//var itemarray=citem.split("&");
-
//return itemarray
-
//}
-
</script>
1 6496 acoder 16,027
Recognized Expert Moderator MVP
See how you can write cookie code. JavaScript is case-sensitive - you can't mix and match.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Robert |
last post by:
Hello all..
Im a beginner in php and looking to do something similar to a shopping
cart system. I want users to be able to view profiles on people and
be able to add them to the "shopping cart" until they decide they are
ready to send a mass email to all the people in their cart. They will
be able to view the people in their cart, add and remove as desired,
and then simply fill out a form and the message will be mailed to all
those in...
|
by: Stuart |
last post by:
Can anyone recomend a good shopping cart script or an example of how to make one.
I'm currently using http://www.mals-e.com free shopping cart script that they host.
unfortunatly because they host the cart themselves I can't hack around and
customise the scripts the way I want.
the linking method I currently use is:
<FORM name="form1" action="http://ww7.aitsafe.com/cf/add.cfm" method="post">
|
by: Jason Burr |
last post by:
I was wondering what the best approach to handling a shopping cart was. My
concerns
1. Cookies not accepted (session variables not maintained and setting
retreiving cookies doesn't work)
2. Use an IP (people behind firewalls or using NAT or other subrouting
appear as same client)
3. Use of GET (people can bookmark cart contents then return and an order
has been fuffilled but shows as new because contents of string are
bookmarked too)
|
by: Jia Sun |
last post by:
hello , everybody , i need a similar program , just like
fancyimport.com
if possible, pls contact me ,thank you very much .
inchina@gmail.com
|
by: zaw |
last post by:
Hi I am working on implementing this script to shopping cart.
Basically, it copies fill the shipping address from billing
automatically. I believe one or more syntax is not netscape
compatible. Can anyone point out which one it is and how to make it
both netscape and MS browser compatible? I hope if I can make the
script compatible for those two at extreme, it will probably work with
most browser out there. As you would notice, this form...
| |
by: Adil Akram |
last post by:
I have created a site shopping cart in ASP.net.
I am using ASP session object's SessionID on non SSL connection to track
session.
While adding products to cart DB I insert product and SessionID in table.
All products and cart status pages are on non SSL connection.
On checkout to get secure user information I shifted connection to SSL but
when shifting to SSL, the SessionID changed (As is this is default behavior
of IIS to prevent...
|
by: isaac2004 |
last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart
page i am having trouble generating 3 numbers; a subtotal, a shipping
total, and a final price. here is my code
i would like it to work properly so that a record count counts through
all the books and genertates these numbers. watch out for line breaks
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
|
by: Milsnips |
last post by:
Hi there,
i had a small project where i used a session to store the shopping cart, but
if it times out, the user loses the cart.
Then i thought instead of using session, i'll store the cart in a cookie,
but cookie only stores string values, which makes it tricky to update/remove
cart item values because i'd have to so substring, split, etc...
What i'm thinking now is to store the cart in a database table, and just add
a cookie with...
|
by: Paulo |
last post by:
Hi, beginner on asp.net 2.0 C# VS 2005, how can I use the shopping cart
concept on my application? When the user clicks add item, it will be stored
on some storage format, I dont know what is the term: temp/global DataSet,
etc... and it should be read on other web-form to checkout the items...
Can you point me to the right direction?
Thank you very much!
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |