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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:59:52+00:00 2026-06-09T01:59:52+00:00

I am trying to create and store a cookie with the jQuery Cookie Plugin.

  • 0

I am trying to create and store a cookie with the jQuery Cookie Plugin. I want to cookie to just be an ordinary counter. I need it to be a cookie because I want to keep the counter going if the page is refreshed. When some condition is true I want, 1 to be added to the cookie value. It seems simple but I am having trouble with using the plugin.

I have created the cookie like this:

$(document).ready(function(){
    $.cookie("cookieValue", "0", { expires: 7 , path: '/' }); 
});

A small example of what I’m trying to achieve:

if (/*some condition*/) {
    cokieValue++;
}

That did not work when the condition was true, the cookie value remained at 0. I also tried:

$(document).ready(function(){
    $.cookie("cookieValue", "0", { expires: 7 , path: '/' });  
    var cookieValue = parseInt($.cookie("cookieValue"));

    if (/*some condition*/) {
        cookieValue++;
    } 
});

This also did not work – cookieValue remained at 0. Any suggestions on how I can accomplish this?

  • 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-09T01:59:53+00:00Added an answer on June 9, 2026 at 1:59 am

    You need to check to see if it exists before you update it with zero.

    if( $.cookie('cookieValue') === null ) { 
        $.cookie( 'cookieValue', '0',  { expires: 7, path: '/' } );
    }
    

    You need to save the value after you update it.

    $.cookie("cookieValue", cookieValue, { expires: 7 , path: '/' })
    

    So the final code would look like

    $(function(){  //shortcut for document.ready
        var cookieVal = $.cookie("cookieValue");  //grab the cookie
        if( cookieVal === null ) {   //see if it is null
            $.cookie( 'cookieValue', '0',  { expires: 7, path: '/' } );  //set default value
            cookieVal = 0;  //set the value to zero
        }
        var cookieValue = parseInt(cookieVal,10);  //convert it to number
    
        if (/*some condition*/) {
            cookieValue++;  //increment the value
            $.cookie("cookieValue", cookieValue, { expires: 7 , path: '/' }); //save new value
        } 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a database. I want to store names and ID's along
I am trying to create an array of buffers. I need to store an
I'm trying to create a website in which I need to store a few
I'm trying a simple if/else statement with Javascript & PHP (with jQuery cookie plugin
I'm trying to create a list of data-id's and store them in a cookie,
I am trying to create a database to store some questions and answers for
I'm trying to create a 2D array to store some values that don't change
I am trying to create an AMI from an instance store instance on amazon
I am trying to create a script that finds the closest store/location to a
I am trying to create a php array where I can store 2 variables

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.