Hi all,
I am newbie to this forum. I am trying set cookies on client m/c using javascript: the code is as below. The fillCookie function fills the cookie values (if present) into the fields on the form. But for some odd reason, when the cookie are not present, the uid field gets filled with a ‘;'(semicolon, i cannot find from where it is getting that) even though there is no cookie present. The pw field works just fine ? . Both use same functions to set and get cookies. The cookies are set from a asp page as:
[CODE]
input id=”myLoginButton” style=”position:relative;top:5;” type=”image” name=”submit” value=”Send” src=”images/login.gif” border=0
onclick=”javascript:setcookie(‘un’,document.forms[0].uid.value,365);setcookie(‘pw’,document.forms[0].pw.value,365);”>
The javascript code is as below:
[CODE]function getcookie(cookiename) {
var cookiestring=””+document.cookie;
var index1=cookiestring.indexOf(cookiename);
if (index1==-1 || cookiename==””) return “”;
var index2=cookiestring.indexOf(‘;’,index1);
if (index2==-1) index2=cookiestring.length;
return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setcookie(name,value,duration){
cookiestring=name+”=”+escape(value)+”;EXPIRES=”+getexpirydate(duration);
document.cookie=cookiestring;
if(!getcookie(name)){
return false;
}
else{
return true;
}
}
function fillCookie()
{
//if the cookies are present then pull them up
alert(getcookie(“un”));
alert(getcookie(“pw”));
if(getcookie(“un”)==’;’) {
document.forms[0].uid.value=””;
}
else {
document.forms[0].uid.value=getcookie(“un”);
}
document.forms[0].pw.value=getcookie(“pw”);
}
Thanks for your help
K