Help with creating a Cookie

Discussion in 'JavaScript' started by bavington, Aug 11, 2009.

  1. #1
    Hi There,

    I'm building an e-commerce website:

    http://www.calusa-surf-ski.co.uk/

    However I'm struggling to get something to work with the navigation on the right hand side, under the search box.

    As you can see, there are 2 seperate navigations for Male & Female. If you click on female, and then navigate away from the page, I would like the website to remember that you have the female navigation currently selected, instead of it always defaulting back to male.

    I assume this should be a straight foward Javascript that generates a cookie, however I'm struggling with my limited knowledge of Javascript.

    Thank you in advance to anyone who can help me.
     
    bavington, Aug 11, 2009 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    You may use this javascript code for creating cookies.

    function createCookie(name,value,days) // fn. for creating cookies
    {
      if (days) 
      {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
         document.cookie = name+"="+value+expires+"; path=/";
    }
    Code (markup):
     
    Unni krishnan, Aug 11, 2009 IP