jquery variables in cookies -
jquery variables in cookies -
this first time i've worked cookies.. i'm using jquery... think problem variables (cararrayxcounter , cararrayxcounter) , pulling value (the number holding.. how sec page read it's value problem... when @ console can see cookie beingness set in first page , beingness read on sec page right value don't know how value out utilize in code. alert tells me cookie undefined.
first page set cookie:
$( document ).ready(function() { var cararrayx = [140,330,460,650,765]; var cararrayxcounter = 0; var cararrayy = [ 440,405,390,390,390]; var cararrayycounter = 0; if (counterbox == 1){ $('#bluecar').animate({ left:cararrayx[cararrayxcounter] + "px", top:cararrayy[cararrayycounter] + "px" }); cararrayxcounter ++; cararrayycounter ++; var cookiexcounter = cararrayxcounter; var cookieycounter = cararrayycounter; console.log(cookiexcounter); console.log(cookieycounter); $.cookie('mycookiex',cookiexcounter,{expires:7,path:'/'}); $.cookie('mycookiey',cookieycounter,{expires:7,path:'/'}); } } second page retrieve cookie:
$( document ).ready(function() { var cookiearrivedx = $.cookie('mycookiex'); var cookiearrivedy = $.cookie('mycookiey'); alert("cookiearrivedx:" + cookiearrivedx); var cararrayx = [140,330,460,650,765]; var cararrayxcounter = cookiearrivedx; var cararrayy = [ 440,405,390,390,390]; var cararrayycounter = cookiearrivedy; $('#bluecar').css({ left:cararrayx[cararrayxcounter], top:cararrayy[cararrayycounter] }); } jquery cookies
Comments
Post a Comment