Hello All,
Sorry to ask very basic question but I'm a little bit rusty at the moment on JavaScript as used it 2 something years ago. I tried some different functions from different posts, but no luck.
I have a project where I need to read a value from URL, set cookie on one page and when user goes to shopping checkout page, retrieve value of my cookie.
I read value from URL and set cookie Ok, as I don't get errors and verify that cookie exist through netscape cookie manager.
But on checkout page, when I try to read cookie, I get Null value. Anything am I doing wrong?
Thanks much.Here's code:
<script language="JavaScript">
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}
function showCookie(){
var myCookie = getCookie("Affiliate_ID")
alert(myCookie);
}
</script>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onLoad="javascript:showCookie()">
Sorry to ask very basic question but I'm a little bit rusty at the moment on JavaScript as used it 2 something years ago. I tried some different functions from different posts, but no luck.
I have a project where I need to read a value from URL, set cookie on one page and when user goes to shopping checkout page, retrieve value of my cookie.
I read value from URL and set cookie Ok, as I don't get errors and verify that cookie exist through netscape cookie manager.
But on checkout page, when I try to read cookie, I get Null value. Anything am I doing wrong?
Thanks much.Here's code:
<script language="JavaScript">
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}
function showCookie(){
var myCookie = getCookie("Affiliate_ID")
alert(myCookie);
}
</script>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onLoad="javascript:showCookie()">