Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:55:02+00:00 2026-06-17T04:55:02+00:00

Having a bit more trouble with Cookies, I did get my site to save

  • 0

Having a bit more trouble with Cookies, I did get my site to save cookies (to-do list items) and reload them after the page had been loaded and place them back into the table on screen.

But, when I deleted all the cookies and tried to start fresh I keep getting a console error saying Cannot read property 'undefined' of undefined Now, if I comment out the below two sections of code, this problem goes away, but the cookie system will fail of course.

This section checks for the number of items that were in the to-do-list last time someone visited, and sets i as that number, so nothing get’s deleted.

var listCookies = document.cookie.split(";");

for(var a = 0; a < listCookies.length; a++) {

    var listCount = myCookies[i].trim().split("=");

    if(listCount[0].indexOf("listCount") === 0) {
        var i = listCount;
    } else {
        var i = 0;
    }
 }

This section finds the actual to-do’s themselves and places them in the table on screen.

var myCookies = document.cookie.split(";");

for(var b = 0; b < myCookies.length; b++) {

    var cookie = myCookies[i].trim().split("=");

    if(cookie[0].indexOf("todo-") === 0) {

        window.todoTable.insertAdjacentHTML('beforeend', decodeURIComponent(cookie[1]));
    }
}

I understand the issue is that there aren’t any cookies saved on someones first visit, but when I tried to add an if (typeof document.cookie === "undefined") statement that didn’t seem to do anything.

I’m assuming I need an if statement wrapped around these pieces of code right? To say, if there isn’t a cookie, ‘skip this bit’. If there is, ‘do stuff’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:55:04+00:00Added an answer on June 17, 2026 at 4:55 am

    i should be global, I have made it totalCount.

    The first section should be:

    var totalCount = 0;
    
    var listCookies = document.cookie.split(";");
    
    for(var a = 0; a < listCookies.length; a++) {
    
        var listCount = listCookies[a].trim().split("=");
    
        if(listCount[0].indexOf("listCount") === 0) {
            totalCount = listCount[1];
            break;
        }
     }
    

    Second section should be:

    var myCookies = document.cookie.split(";");
    
    for(var b = 0; b < myCookies.length; b++) {
    
        var cookie = myCookies[b].trim().split("=");
    
        if(cookie[0].indexOf("todo-") === 0) {
    
            window.todoTable.insertAdjacentHTML('beforeend', decodeURIComponent(cookie[1]));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a bit of trouble using the List.Find with a custom predicate i have
Im having a bit of trouble understanding the more complex system calls in assembly.
I'm doing a proof of concept thing here and having a bit more trouble
I'm having a bit of trouble trying to get this quicksort algorithm to work
Having a bit of trouble wrapping my head around this one. I'm sure the
Im having a bit of trouble getting my JSON to be recognised by my
I'm having a bit of trouble loading an html file in a WebView control
I'm having a bit of trouble with a a function that the mongodb c
I'm having a bit of trouble with jQuery Deferred. I'm using a jQuery ajax
I'm having a bit of trouble figuring out what would be the best approach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.