Results 1 to 2 of 2

Thread: Setting cookie with prompt.

  1. #1
    Join Date
    Apr 2012

    Setting cookie with prompt.

    Hi everyone. I am trying to get my delivery schedule set.
    What I am looking for is a way for users to input their zip codes, and a popup come up detailing the minimum order for free delivery.

    I want to create a cookie for this as well, for repeat customers, but I also need to be able to drop the cookie to select a new zip code. Here is what I have so far...

    HTML Code:
    <script type="text/javascript">
    function getCookie(c_name)
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
      if (x==c_name)
        return unescape(y);
    function setCookie(c_name,value,exdays)
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    function checkCookie()
    var zipcode=getCookie("zipcode");
    if (zipcode!=null && zipcode!="")
      alert("Your Shipping Zip-Code is: " + zipcode);
      <!-- Function to Change Zip-Code, or empty cookie !-->
      zipcode=prompt("Please enter your Zip-Code:","");
      if (zipcode!=null && zipcode!="")
      else if(zipcode==32218);
      alert(" Minimum order for Delivery is: $500.00")
      else if (zipcode==35983);
      alert("Minimum order for Delivery is: 300.00")
      alert("We do not deliver in your area.");
    <body onload="checkCookie()">
    It is not working.

    Thanks for any help.

  2. #2
    Join Date
    Dec 2002
    St. Louis, MO, USA
    In your for loop, x is always set to a substring that always starts at 0.
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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