1

How can we store dynamic variables into cookie .

var username = ($("#username").val());

how to store the variable username into jquery cookie variable

$.cookie('username', '+username +');
alert($.cookie('username'));
Sergio
  • 28,539
  • 11
  • 85
  • 132
mahesh
  • 3,067
  • 16
  • 69
  • 127

1 Answers1

4

If you put within a single quotes it takes only string.So for this you don't need the single quotes for assigning the value.

Try this

$(document).ready(function() {
    var username = ($("#username").val());
    $.cookie('username', username ); 
    alert($.cookie('username'));  
});

It works for me.

Jonathan Drapeau
  • 2,610
  • 2
  • 26
  • 32
svk
  • 4,513
  • 18
  • 63
  • 100