Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having problems creating and getting cookies

Status
Not open for further replies.

rosesau

Programmer
May 24, 2001
9
AU
hi i am getting errors when trying to set and read a cookie.

the set cookie code goes like this
function getexpirydate(nodays){
var UTCstring;
Today = new Date;
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring=Today.toUTCstring();
return UTCstring;
}
function setcookie(name,value,duration){
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
document.cookie=cookiestring;
}

i get the following error - object does'nt support this property or method on line 32 which happens to be the following
Today.setTime(nomilli+nodays*24*60*60*1000);

when i try to read the cookie i also get an error. the get cookie code is as follows

function getcookie(cookiename) {
var cookiestring=""+document.cookie;
var index1=cookiestring.indexOf(cookiename);
if (index1==-1 || cookiename==""){
return"";
window.location="login.htm";
}
var index2=cookiestring.indexOf(';',index1);
if (index2==-1) index2=cookiestring.length;
return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
var loggedin = getcookie("jpc");
if (loggedin!=true) window.location="login.htm";

the error i get is syntax error on line 41 which happens to be the following

if (loggedin!=true) window.location="login.htm";

any help that you could give would be great.

thanks
rose
 
ok i have realised that i forgot to close of the function when i am trying to read the cookie. however i am still having problems with the setcookie function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top