Jump to content

Creating Cookies? Not Working Correctly


dzhax
 Share

Recommended Posts

I have this code for making a cookie.

function popup_show(remove_id){  document.cookie = 'remove=something';}

that will make the cookie remove with a value of somthingnow if i do this

function popup_show(remove_id){  document.cookie = remove_id;}

or

function popup_show(remove_id){  document.cookie = escape(remove_id);}

It does not set the cookie. It leaves it NULL.remove_id = 'remove=11' when sentCan someone help?

Edited by dzhax
Link to comment
Share on other sites

If you escape it, the '=' will lost its meaning. Try encodeURI() rather than escape.Try checking what the parameter is inside the function:

function popup_show(remove_id) {  alert(remove_id);  document.cookie = remove_id;}

Edited by Ingolme
Link to comment
Share on other sites

typical cookie setting and getting script:

function set_cookie( name, value, exp_y, exp_m, exp_d, path, domain, secure ) {  var cookie_string = name + "=" + escape ( value );  if ( exp_y )  {    var expires = new Date ( exp_y, exp_m, exp_d );    cookie_string += "; expires=" + expires.toGMTString();  }  if ( path )        cookie_string += "; path=" + escape ( path );  if ( domain )        cookie_string += "; domain=" + escape ( domain );    if ( secure )        cookie_string += "; secure";         document.cookie = cookie_string;  }function get_cookie(cookie_name){  var results = document.cookie.match( '(^| ?' + cookie_name + '=([^;]*)(;|$)' );  if ( results )    return ( unescape ( results[2] ) );  else    return null;}function setthiscookie(remove_id){  set_cookie("remove_id", remove_id);}function getthiscookie()    {    var thiscookievalue = get_cookie("remove_id");     }

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...