SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cannot access cookie name- name undefined in the next page

    HI all,

    I cannot access the cookie name created from a main page.

    ////////mainpage
    .....

    document.cookie = "moduleName="+escape(document.getElementById('ModuleName').value);
    ....
    /////// end main page

    /////// JS file (link.js)!!!!!!!

    function getCookie(moduleName)

    {
    cookieValue = "";
    if (document.cookie.indexOf(moduleName) == -1)
    {
    alert("there is no cookie by this name for this user");
    return cookieValue;
    }
    else
    {
    cookieStart = document.cookie.indexOf(moduleName);
    cookieValStart = (document.cookie.indexOf("=", cookieStart) + 1);
    cookieValEnd = document.cookie.indexOf(";", cookieStart);
    if (cookieValEnd == -1)
    {
    cookieValEnd = document.cookie.length;
    }
    cookieValue = document.cookie.substring(cookieValStart,cookieValEnd);
    return cookieValue;
    }

    } //end getCookie


    ////another page (pop up dialog ) within active session/browser

    ModuleName =getCookie("moduleName"); //this is where I got "moduleName" undefined?????

    Any thoughts on why? Thanks

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tvfoto View Post
    ModuleName =getCookie("moduleName"); //this is where I got "moduleName" undefined?????

    Any thoughts on why? Thanks
    Is the second page in a higher folder?

    Try:
    Code:
    document.cookie = "moduleName="+escape(document.getElementById('ModuleName').value);+';path='/';
    Tab-indentation is a crime against humanity.


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
  •