Visit Our Home Page
 Explored,Designed,Delivered.sm
Welcome, Guest. Please Login or Register (Password Reminder)


Creativyst Forums 
Support & Discussion 
Register Help Search Login  
   
   Creativyst Forums-TOP
   Web Site Design
   Shopping cart with JavaScript and XML...need help!
(Moderator: admin)
 Author
Topic: Shopping cart with JavaScript and XML...need help!       [Link=88]
Reply Please log in first.
hawk78
New Member


Posts: 1




     
    Shopping cart with JavaScript and XML...need help!   (Date posted: 05/21/04 at 16:01:13) Quote Modify Delete

Hello,

I'm trying to set up a shopping cart system by using JavaScript and XML. I'm relatively new to both of them so I've gathered my source code from various of sources and the result is that the cart doesn't work..

I assume that the problem has got something to do with xml, because the code itself worked the products weren't in an xml-file.

So, please! Any comments would be highly appreciated.

Here's the code so far:
********
<html>
<body>

<SCRIPT LANGUAGE="JavaScript">
function buyItem(newItem, newPrice, newQuantity) {
newItem = document.form1.TITLE.value;
newPrice = document.form1.PRICE.value;
newQuantity = document.form1.COUNT.value;

if (newQuantity <= 0) {
rc = alert('Zero is not a quantity.');
return false;
}
if (newQuantity >= 0) {
index = document.cookie.indexOf("MyCart");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
window.location = "basket.htm";
}
document.cookie="MyCart="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newPrice+"^"+newQuantity+"]";
}
return true;
}
function resetShoppingCart() {
index = document.cookie.indexOf("MyCart");
document.cookie="MyCart=.";
}
</SCRIPT>

<xml id="myProducts" src="cd_catalog.xml"></xml>
<table border="1" datasrc="#myProducts">
<form name="form1">
<td><span datafld="ARTIST" DATASRC="#myProducts" DATAFLD="ARTIST"></span></td>
<td><span datafld="TITLE" DATASRC="#myProducts" DATAFLD="TITLE"></span></td>
<td><button ID="PRICE" DATASRC="#myProducts" DATAFLD="PRICE" onClick="buyItem('','',1);"></button></td>
<td>Quantity:<input id="COUNT" size=2 maxlength=2 value=1></td>
</form>
</table>

</body>
</html>
********
Here's the XML-file:

The page can also be found at:

and the "basket" at:

   E-Mail   Ip: Logged
JRepici
Administrator


Posts: 328





Gender:
      JohnRHere2
    Re: Shopping cart with JavaScript and XML...need h   (Date posted: 05/21/04 at 16:01:53) Quote Modify Delete

Not sure. Maybe a lurker can help?

-John

   E-Mail   Ip: Logged
Reply Please log in first.
Pages: 1
Jump to:

YaBB Board c 2000
YaBB Programming Team
 



















© Copyright 2002 - 2008 Creativyst, Inc.