Cookies to store Javascript values

0

I would like you to help me with a problem. What I want is to use cookies to store a value this is the code

document.cookie="bandera=0;";

$(document).ready(function(){

var lascookies = document.cookie;
alert(lascookies);

$("#btn2").click(function() {
    document.cookie = "bandera=1;";
    $('#pum-55').hide();
    });
});

With this when loading the page I created a cookie flag name and a value 0, now when I press the% button btn2 I want to change the value of cookie by value 1.

But when I reload the flag page it is again with value 0. Could someone help me to maintain that value?

    
asked by Ernesto Emmanuel Yah Lopez 08.06.2017 в 16:03
source

1 answer

1

Change your code to the following

// Si la cookie no existe, la creas dandole el valor de cero
    if( !document.cookie == "bandera=0;" ){
       document.cookie = "bandera=0;";
    }


$(document).ready(function(){

var lascookies = document.cookie;
alert(lascookies);

$("#btn2").click(function() {
    document.cookie = "bandera=1;";
    $('#pum-55').hide();
    });
});
    
answered by 08.06.2017 / 16:15
source