SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Passing Username along to other pages in JS with cookies

    I am trying to set up a page that will allow a user to enter their name into a text field and click a submit button. When the button is clicked, the name that the user entered is passed into a cookie, and displayed on the page at the same time.

    However, I am having issues getting the name (i.e. the value of the cookie) to be passed along to other pages within the site as well.

    I am using jquery to code the JS with. I have the first page all set up and it works beautifully, but when I try to use the getter for the cookie on the second page I get nothing. I am using a cookie plugin for jquery that I found here.

    Any help on tis would be great.

  2. #2
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it even possible to retrieve a cookie value that is set on one page from another page on the same site?

    Or should this just be done with php?

  3. #3
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all that can be done with javascript cookies, but it won't work in browsers where cookies are switched off by the user.

    you might be better off storing the username in a php session.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by averagejoe77 View Post
    Is it even possible to retrieve a cookie value that is set on one page from another page on the same site?
    Yes it is. You should ensure that the path the cookie is set with is at a high-enough common location. Typically '/' is used for a site-wide accessible cookie.
    The page that you linked to provides detailed information on how to set a path for a cookie.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •