By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,689 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,689 IT Pros & Developers. It's quick & easy.

my set_cookie() function is not working

P: 2
Hie....my set_cookie function is not working. I dont know why it is happening as there is no error also...i am setting it through javascript.......

Expand|Select|Wrap|Line Numbers
  1. var live_element;
  2. function fokus(ele,path) 
  3. {
  4.     //alert(ele);alert(path);return false;
  5.     live_element = ele;
  6.     //alert(live_element.id);    //LIKE C_NAME
  7.  
  8.     if(Get_Cookie('live_element'))     //Go to 873
  9.     {
  10.         Delete_Cookie( 'live_element');
  11.     }
  12.     Set_Cookie( 'live_element', live_element.id,'',path,'','' );
  13.     //Set_Cookie( name, value, expires, path, domain, secure )
  14. }
  15.  
  16. function Set_Cookie( name, value, expires, path, domain, secure ) 
  17. {
  18.  
  19. // set time, it's in milliseconds
  20. var today = new Date();
  21. today.setTime( today.getTime() );
  22.  
  23. /*
  24. if the expires variable is set, make the correct 
  25. expires time, the current script below will set 
  26. it for x number of days, to make it for hours, 
  27. delete * 24, for minutes, delete * 60 * 24
  28. */
  29. if ( expires )
  30. {
  31. expires = expires * 1000 * 60 * 60 * 24;
  32. }
  33. var expires_date = new Date( today.getTime() + (expires) );
  34.  
  35. document.cookie = name + "=" +escape( value ) +
  36. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
  37. ( ( path ) ? ";path=" + path : "" ) + 
  38. ( ( domain ) ? ";domain=" + domain : "" ) +
  39. ( ( secure ) ? ";secure" : "" );
  40.  
  41. }
  42.  
Here , the 'live_element' named cookie is not generated...what could be the problem?
Aug 27 '09 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,390
when you pass '' as the expires param then your function will produce an invalid date for expires_date ... you could fix that with an adapted condition:

Expand|Select|Wrap|Line Numbers
  1. if ( expires ) {
  2.     expires = expires * 1000 * 60 * 60 * 24;
  3. } else {
  4.     expires = 0;
  5. }
  6.  
kind regards
Aug 30 '09 #2

P: 2
yap.....i'll try this one and see.....
Sep 3 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.