Cookies function with shopping cart

Source: Internet
Author: User
Tags setcookie
cookie| Shopping cart cookies function with shopping cart
ZiF posted on 2000-01-11 16:13:00

Wandering on the internet, found a good dongdong, the idea is good!
Can be used in small online stores.
I listed below the source code, we make good use of!
What a good experience, tell me Oh!
------------------------------------
Products.html
<title>claremont toyworld</title>
<script language= "JAVASCRIPT" >
function Setcookie (name, price, form) {
Document.cookie= Document.cookie + ":" + name + ":";
document.cookie= Document.cookie + "" + ":";
Document.cookie= Document.cookie + price + ":";
document.cookie= Document.cookie + "" + ":";
document.cookie= Document.cookie + "|" + ";";
}
</script>
<body text= "#000000" bgcolor= "#FFFF00" link= "#0000EE" vlink= "#551A8B" alink= "#FF0000" >
<a href= "trolley.html" >here.</a>
<table border= "0" cellspacing= "0" cellpadding= "0" cols= "3" width= "75%" >
<tr>
<td><strong>Furby</strong></td>
<td>the Amazing pet</td>
<td><small>AUD</small> $69.95<font size= "-2" > + <a href= "#Postage" >postage</a> </font></td>
<td><form>
<p><input type= "button" value= "Add to Cart" name= "Additem1"
onclick= "Setcookie (' Furby ', ' 69.95 ', this.form);" ></p>
</form>
</td>
</tr>
</table>
</body>
----------------------------------------
Trolley.html
<script language= "JAVASCRIPT" src= "Trolley.js" >
</script>
<body>

<table cols=2 width= "100%" >
<tr>
<td>
</td>
</tr>
</table>
<form name= "trolleycontents" action= "formmail.pl" method= "POST" ><input type= "hidden" name= "email" value= " Email ">

<script language= "JAVASCRIPT" >
Tableofnrows (Numberofitems (Document.cookie, Option_separator, Item_separator));
</script>

<table cols=4 width= "100%" >
<tr>
<td><input type= "button" value= "<--back to Shopping" onclick= "window.close ();" ></td>

<td><input type= "button" value= "clear shopping Trolley" onclick= "Cleartrolley ();" ></td>

<td> <a href= "#Finalise" >finalise order</a></td>

<td> </td>
</tr>
</table>

<script language= "JAVASCRIPT" >
Totaltable ();
</script>

</body>
----------------------------------------
Trolley.js
rem trolley.js source Copyright Prestige Training Centre

Option_separator = ":";
Item_separator = "|";

function Numberofitems (string, Option_separating_char, Item_separating_char) {
Returns the number of trolley items

if (string = = "") {
Alert ("Your shopping trolley is currently empty.");
return 0;
}

Count the number of item separators
Num_sep_found = 0;
Num_fin_found = 0;
Finished =-1;
pos = 0;
while (finished!=1)
{
if (String.charat (pos) = = Option_separating_char) num_sep_found++;
if (String.charat (pos) = = Item_separating_char)
{
num_fin_found++;
if (String.charat (pos+1)!= Option_separating_char) finished=1;
}
pos++;
}

Divide by the number of ' ends ' found

Num_sep_found = Num_sep_found-num_fin_found;

if (Num_fin_found >0) return num_sep_found/num_fin_found;

return num_fin_found;

}

function Cleartrolley () {
if (Confirm ("clear the contents of your shopping trolley?")
{
Document.cookie= "";
History.back ();
}
}

function GetElement (terminator,index,string) {

Find Nth Terminator
pos = 0;
For (Inc=1 inc<index+1; Inc



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.