SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    home, kent
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookies and a shopping cart problem

    Hey all, I'm having such a dilemma with what is probably a simple cookie shopping cart page. My problem is that I need to store some values in a cookie, then simply transfer and split the information to the checkout page and present it in a table. I've got most of the basic structure done, it's just the inbetween bits that are driving me crazy.

    I've only included the checkout and item 'add to cart' pages as I didn't want publish my whole site (simply because there would be too much to read!!).

    I hope I've explained myself well enough. I would be so very grateful if anyone can help!!!?? Thanx.


    Lukas


    add to cart - item page.

    <SCRIPT LANGUAGE="Javascript">
    <!--

    var i = location.search.substring(3,location.search.length)

    document.write("<BODY BGCOLOR='#00CC66' TEXT='#330000'><DIV ALIGN='center'>");

    document.write("<TABLE WIDTH ='75%'><TR><TD COLSPAN ='2' ALIGN ='center'>");

    document.write("<FONT SIZE ='6'><B>Item: </B><FONT COLOR ='white'> " + video[i].item_ + "</FONT></TD></TR><HR>");

    document.write("<TR><TD>ID: <FONT COLOR ='white'> " + video[i].id + "</FONT></TD></TR>");

    document.write("<TR><TD>Description: <FONT COLOR ='white'> " + video[i].description + "</FONT></TD></TR>");

    document.write("<TR><TD>Year Released: <FONT COLOR ='white'> " + video[i].year + "</FONT></TD></TR>");

    document.write("<TR><TD>Price: <FONT COLOR ='white'> " + video[i].price + "</FONT></TD></TR>");

    document.write("</TABLE>");

    document.write('<input type="button" value="Back" onClick="history.back();">');

    function setCookies() {

    var k = video[i].item_;
    var j = video[i].price;

    document.cookie='names =' + escape(k);
    document.cookie='spend =' + escape(j);


    }

    //-->
    </SCRIPT>
    <INPUT TYPE="button" VALUE="Check your Cart" onClick="alert(unescape(document.cookie))">
    <INPUT TYPE="button" VALUE="Add to Cart" onClick="setCookies()">

    ----------------------------------

    checkout page.


    <SCRIPT LANGUAGE="Javascript" SRC="catalogue.js">
    <!--

    if (document.cookie && document.cookie == "");

    {processCookie()
    }

    else {alert("There is nothing in your basket");

    }


    fucntion processCookie(){

    var whole = unescape(document.cookie);
    var single = whole.split(";");

    for (m=0; m<single.length; m++){

    if (single[i].indexOf("names") > -1){var namesdata = single[i];
    if (single[i].indexOf("spend") > -1){var spenddata = single[i];

    }

    var namesplit = namesdata.split("=");

    var product = namesplit[0];


    var spendsplit = spenddata.split("=");

    var amount = spendsplit[0];

    if (product == ""){product = "none entered";}
    if (amount == ""){amount = "none entered";}

    }



    var i = location.search.substring(3,location.search.length)

    document.write("<TABLE BORDER = '1' BORDERCOLOR = 'white' BGCOLOR= 'gray' CELLSPACING = '5' CELLPADDING = '5'>");

    document.write("<TH COLSPAN ='4'>CHECKOUT</TH>");

    for (i=0; i<[i].length; i++){

    document.write("<TR><TD>" + product + "</TD><TD>" + amount + "</TD>");

    document.write("<TD><INPUT TYPE='text' NAME='quant' VALUE='1' SIZE='2'></TD></TR></TABLE><BR><HR>");

    document.write("<FORM NAME='upForm'>");

    document.write("<INPUT TYPE='button' NAME='upDate' VALUE='Update' onClick='updateCartCookie()'>");

    document.write("</FORM>");

    }

    //-->
    </SCRIPT>



    ----------------------

    Thanx again!
    Last edited by lukastroy; Jan 5, 2005 at 11:06. Reason: title clarity

  2. #2
    SitePoint Member
    Join Date
    Dec 2004
    Location
    home, kent
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to close this thread and say I did it, and sorry if anyone read my code and noticed the few obvious mistakes! Sorry.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •