How to get cookie value using jQuery JS cookie

I use a jQuery cookie plugin called JS Cookie , and it happens that I can’t get the data or value in a cookie, I would like to save the cookie value that was entered in the text box and get it in the text box when the page is visited again .

$(document).ready(function() {
    var cookie_email = Cookies.get('user_email');
    $('#email_address').val(cookie_email);

    $('#test_button').click(function() {
        Cookies.set('user_email', email_address, {
            expires: 365
        });
    });
});

https://jsfiddle.net/mue1amcm/

+4
source share
1 answer

Your code does not work because you are not assigning a variable email_addressanywhere. You must change this value to use $('#email_address').val().

, jsFiddle ; URL- cookie script Github. CDN. :

var cookie_email = Cookies.get('user_email');
$('#email_address').val(cookie_email);

$('#test_button').click(function() {
    Cookies.set('user_email', $('#email_address').val(), {
        expires: 365
    });
});

+5

All Articles