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
  • 27,998
  • 10
  • 81
  • 130
mahesh
  • 2,887
  • 16
  • 65
  • 124

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,619
  • 2
  • 25
  • 32
svk
  • 4,325
  • 17
  • 60
  • 100