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 6646315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:24:06+00:00 2026-05-26T00:24:06+00:00

first time poster, long time reader. So I needed to create a quick and

  • 0

first time poster, long time reader.

So I needed to create a quick and simple treasure hunt. The ideas was to store some values in a cookie and, when the user click on an element with a matching id, update the following value. It’s not in there yet but when the person has found all 8 (in this case) it will trigger something.

Now, I’ve gotten it to mostly work but I’m running in to a big problem. The cookie is not being stored from page to page. If I’m working off a single test page it’s just fine – the cookie is created, values are pulled from it and put in to a check array, and the counter increments correctly. Also, when the cookie is updated the new values are being stored just fine.

However, when I go to another page and check for the cookie – it’s gone. Now I checked to see if the cookie was actually getting dropped in and yes, it’s there. But there are multiple cookies all with the same name (they are updating values – but again it’s only page to page so no cumulative effect).

So, I guess I don’t understand why when I call the cookie and reset it, it’s not affecting a single cookie but creating a new one?

Oh, I’m using jQuery 1.4.2 and the jQuery cookie plugin.

// if not present create default array and store in cookie cookie
if($.cookie('treasure_hunt') == null) {

var treasure = new Array(
    "arteContactEn",0,
    "arteCorpEn",0,
    "arteServicesEn",0,
    "arteRoomsEn",0,
    "arteDiningEn",0,
    "artePackEn",0,
    "arteHotelEn",0,
    "arteHomeEn", 0
)
   $.cookie('treasure_hunt', treasure, { expires: 7 });
}

// capture cookie info
var treasureFound = $.cookie('treasure_hunt');

// create check array and parse values into it
var treasureCheck = new Array();
var treasureCheck = treasureFound.split(',');

// function checks array and tallies total found items
function checkFound() { 
var foundItems = 0;

for(var i=0; i<treasureCheck.length; i++) {
    var value = treasureCheck[i];
    if(value == 1) {
        ++foundItems;
    }
}
// writes found items to span on page
$('.thProgress').text(foundItems);

}

// check number artefacts and write to page
var treasureTotal = treasureCheck.length / 2;
$('.thTotal').text(treasureTotal);

// on click checks element id against array and, if found, marks the following value as 1
$('.artefact-right, .artefact-left').click(function(){
var artefactID = $(this).attr('id');

for(var e=0; e<treasureCheck.length; e++) {
    var matchID = treasureCheck[e];
    var k = e + 1;

    if(matchID == artefactID) {
        treasureCheck[k] = 1;

        // checks for total found items
        checkFound();

        // updates cookie with new array
        $.cookie('treasure_hunt', treasureCheck, { expires: 7 });
    }

}

});
  • 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-05-26T00:24:06+00:00Added an answer on May 26, 2026 at 12:24 am

    According to the README file in github, you need to define the path the cookie is valid for if you don’t want it to be only for the page it was created on:

    Define the path where cookie is valid. By default the path of the
    cookie is the path of the page where the cookie was created (standard
    browser behavior).
    If you want to make it available for instance
    across the entire page use path: ‘/’. If you want to delete a cookie
    with a particular path, you need to include that path in the call.

    So I think it would be something like this:

    $.cookie('treasure_hunt', treasure, { expires: 7, path: '/' });
    

    P.S. You’re missing a semicolon at the end of your var treasure = new Array() declaration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first time poster, long time reader so be gentle with me :) See the
long time reader/first time poster here. So I've got a checkbox array that posted
Long time reader, first time poster asks: After many weeks of google and forum
Long time reader, first time poster. I'm a big noob when it comes to
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
long time reader, first time poster. I’m coming with an issue that many of
Long time reader, first time poster. Working on a web site at http://www.howardpitch.com/ ,
First time poster, long time reader. I searched and found no questions that answered
I'm a long time reader first time poster, glad to start participating in this
Long time reader, first time poster. One day I hope to be answering questions

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.