Article View: comp.lang.javascript
Article #57Problem basket boutique
From: Juliette
Date: Tue, 05 Sep 2000 10:53
Date: Tue, 05 Sep 2000 10:53
150 lines
6167 bytes
6167 bytes
Hello,
I meet a big problem at the level of the basket, of a boutique (file
voir.js)
The customers can not command more than 20 articles different .
The 21-th article erases the 1-st.
Could you indicate to me lines concerned JavaScript ?
(I am not very good in Javascript .....)
How make possible order with one unlimited number of articles ?
Thank you in advance.
Warmly,
Juliette from France.
function view_cart() {
mycookies=new Array(20);
var i=0;
var startpoint=0;
whole_len=document.cookie.length;
while(whole_len!=startpoint && i< 20)
{
if ((temlen=document.cookie.indexOf(";",startpoint))!=-1)
{
mycookies[i]=document.cookie.substring(startpoint,temlen);
i++;
startpoint=temlen+1
}
else if (startpoint != whole_len)
{
mycookies[i]=document.cookie.substring(startpoint,whole_len);
i++;
startpoint=whole_len;
}
}
printtitle();
for (j=0;j<i;j++)
{
file://filter out cookies that are not used by shopping cart
if((mycookies[j].substring(0,4)=="crea")||(mycookies[j].substring(0,5)=="
crea"))
getCookie(mycookies[j]);
}
document.write("</table>");
}
function getCookie (acookie) {
clen = acookie.length;
nlen= acookie.indexOf("=",0);
file://get rid of the "crea" at the beginning, thus start at 4
if(acookie.substring(0,1)==" ")
cname=acookie.substring(5,nlen);
else
cname= acookie.substring(4,nlen);
bname= acookie.substring(nlen+1,clen);
sname_len=cname.indexOf("+",0);
store=cname.substring(0,sname_len);
dlen=cname.indexOf("+",sname_len+1);
descrip=cname.substring(sname_len+1,dlen)
product=cname.substring(dlen+1,nlen);
qlen=bname.indexOf("+",0);
rlen=bname.indexOf("+",qlen+1);
quant=bname.substring(0,qlen);
if(quant==0)
document.cookie="crea"+cname+"=bb; expires=Saturday, 16-Sep-90 23:59:59
GMT; path=/"+"";
refer=bname.substring(qlen+1,rlen);
price=bname.substring(rlen+1,clen-nlen)*quant;
price=price_format(price);
printcontent();
}
function putback(str1){
document.cookie="crea"+str1+"=bb; expires=Saturday, 16-Sep-90 23:59:59
GMT; path=/"+"";
}
// There's no need to touch anything above this line
// You can use "store","descrip","product","quant","price"
// and "refer" in the code below
function printtitle(){
tabletitle="<TABLE WIDTH=500 BORDER=0 BGCOLOR=#000000 ALIGN=CENTER><tr> \
<TD WIDTH=100><FONT SIZE=2 FACE=Arial
COLOR=#FFFFFF><B>Produit</B></FONT></td> \
<TD WIDTH=250><FONT SIZE=2 FACE=Arial
COLOR=#FFFFFF><B>Désignation</B></FONT></td> \
<TD WIDTH=50 Align=CENTER><FONT SIZE=2 FACE=Arial
COLOR=#FFFFFF><B>Qté</B></FONT></td> \
<TD WIDTH=100 align=RIGHT><FONT SIZE=2 FACE=Arial COLOR=#FFFFFF><B>Montant
TTC </B></FONT></td> \
<td> </td></tr>";
document.write(tabletitle);
}
function printcontent(){
if(quant!=0){
document.write("<tr align=LEFT><TD WIDTH=100 BGCOLOR=#FFFFFF
VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>"+product+"</B></FONT></td><TD
WIDTH=250 BGCOLOR=#FFFFFF VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>");
document.write(descrip+"</B></FONT></td><TD WIDTH=50 BGCOLOR=#FFFFFF
Align=CENTER VALIGN=TOP><FONT SIZE=2
FACE=Arial><B>"+quant+"</B></FONT></td><TD WIDTH=100 BGCOLOR=#FFFFFF
align=RIGHT VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>");
document.write(price+"</B></FONT></td>");
document.write("<TD><form><input type=submit value=Enlever ");
document.write("onClick=\"putback(\'"+store+"+"+descrip+"+"+product);
document.write("\')\"></form></td></tr>");
}
}
file://add a field so that shopper can change amount of product in cart
function printcontent2(){
if(quant!=0){
document.write("<tr align=center><td BGCOLOR=#FFFFFF>"+product+"</td><td
BGCOLOR=#FFFFFF>");
document.write(descrip+"</td><td BGCOLOR=#FFFFFF><form method=get ");
document.write("action=voir.html><input type=text size=3");
document.write(" name=quantity value="+quant+">");
document.write("<input type=hidden name="+price);
document.write(" value=\""+descrip+"\">");
document.write("<input type=hidden name=\""+product);
document.write("\" value=\""+store+"\"></td><td>");
document.write(price+"</td><td BGCOLOR=#FFFFFF>"+"<a
href="+refer+">"+store+"</a>");
document.write("</td><td BGCOLOR=#FFFFFF><input type=submit value=update
onClick=");
document.write("addtocart(this.form,'voir.html')>");
document.write("</form></td></tr>");
}
}
function price_format(tmpprice){
// get rid off the extra digits behind "."
dot = tmpprice.toString().indexOf(".");
if(dot!=-1)
tmpprice=tmpprice.toString().substr(0,dot+4);
tmpprice=Math.round(tmpprice*100)/100;
// add "0" if necessary
dot = tmpprice.toString().indexOf(".");
if(dot ==-1)
tmpprice=tmpprice.toString()+".00";
else if((tmpprice.toString().length-dot)==2)
tmpprice=tmpprice.toString()+"0";
return tmpprice;
}
Technical Details
Message-ID:
<8p2bo7$20g$1@wanadoo.fr>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-east!sn-xit-uk!supernews.com!193.162.153.122.MISMATCH!news.tele.dk!195.25.12.36!oleane.net!oleane!wanadoo.fr!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10731d,9ed9835f51f6a61d,start X-Google-Attributes: gid10731d,public X-Google-Thread: fb3cb,9ed9835f51f6a61d,start X-Google-Attributes: gidfb3cb,public X-Google-ArrivalTime: 2000-09-05 01:44:03 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-east!sn-xit-uk!supernews.com!193.162.153.122.MISMATCH!news.tele.dk!195.25.12.36!oleane.net!oleane!wanadoo.fr!not-for-mail From: "Juliette" <juliette.freudenberg@wanadoo.fr> Newsgroups: comp.lang.javascript,borland.public.intrabuilder.javascript Subject: Problem basket boutique Date: Tue, 5 Sep 2000 10:53:12 -0000 Organization: Wanadoo, l'internet avec France Telecom Lines: 157 Message-ID: <8p2bo7$20g$1@wanadoo.fr> NNTP-Posting-Host: mix-puteaux-102-104.abo.wanadoo.fr X-Trace: wanadoo.fr 968143431 2064 193.250.190.104 (5 Sep 2000 08:43:51 GMT) X-Complaints-To: abuse@wanadoo.fr NNTP-Posting-Date: 5 Sep 2000 08:43:51 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211