| <SCRIPT>
// we are making
the assumption that these arrays were pulled out of a database var Price = new Array(32, 16, 8, 4); /*************** Cookie Functions ***************/ var thisCookie = document. cookie;function getCookie(name) {var index = thisCookie.indexOf(name + "="); if (index == -1) return null; index = thisCookie.indexOf("=", index) + 1; var endstr = thisCookie.indexOf(";", index); if (endstr == -1) endstr = thisCookie.length; return unescape(thisCookie.substring(index, endstr));} function setCookie(name, quantity) {if (value != null && value != "") document.cookie = name + "=" + quantity; thisCookie = document. cookie;} function deleteCookie(name,
path, domain) { /*************** End of Cookie Functions ***************/ // When we add an item we need to
make a few checks var name = Item[i]; var quantity = document.orderForm[name].value; //
Is the quantity a number? //
take of the situation, ie, 01 make it 1 //
Is there a quantity or is the quantity zero if (!quantity)
{ setCookie(name, quantity);
cart = getCookie("cart");
// get the
contents of the dynamic cart cookie
if (!cart) { // if
the cart doesn't exist then create it setCookie("cart",
cart); // create
the cart cookie /* </SCRIPT> < BODY onLoad="upDate();">< FORM NAME="orderForm">< TABLE BORDER="1" CELLPADDING="5">< TR><TD BGCOLOR="#336699"> <FONT COLOR="#FFFFFF">Item Description</FONT> </TD> <TD BGCOLOR="#336699"> <FONT COLOR="#FFFFFF">Quantity</FONT> </TD> <TD BGCOLOR="#336699"> <FONT COLOR="#FFFFFF">Unit Price</FONT> </TD> <TD BGCOLOR="#336699"> </TD> </TR> <TR> <TD> Panda </TD> <TD> <INPUT TYPE="text" NAME="Panda" VALUE="0" SIZE="3"> </TD> <TD> $32 </TD> <TD> <A HREF="javascript:addCookie(0);" onMouseOver="status='Add the Item to the Shopping Cart'; return true;" onMouseOut="status='';"> <IMG SRC="images/addtocart.gif"> </A> </TD> </TR> etc... < /TABLE>< /FORM>< A HREF="checkout.htm"onMouseOver="status='Take Me to the Check Out'; return true;" onMouseOut="status='';"> <IMG SRC="images/checkout.gif"> </A> In this exercise a dynamic cart is created. If an Item is added then cart will "hold" this particular item. A price string will also be created that matches the cart contents. In the checkout if an item is deleted is deleted then that item will be deleted from the cart and the price from the price string. |