View Full Version : Cookie Problem

12-18-2004, 08:17 AM

I am using the following coding for accessing the cookie.
dokie = document.cookie
start = dokie.indexOf("name=")+"name=".length;
end = dokie.indexOf(";", start);
if(end==-1)end = dokie.length
document.write(dokie.substring(start, end))

After entering the username, the username is stored in the cookie and it is accessed in another page as "Welcome Jackson"

But if i close the ie window again i go to that same url then i am getting as t=2 instead of jackson(username).
Please Help me.


12-18-2004, 10:49 AM
Heres an example of what I kinda do when I set and Get cookies:

<script language="javascript">
var expires = new Date();
expires.setFullYear(expires.getFullYear() + 1);
function set()
var name1 = document.forms[0].firstName.value;
document.cookie = encodeURI("fname="+name1) + "; expires=" + expires.toUTCString();
function getCookie()
var cookie = decodeURI(document.cookie);
var splitCookie = cookie.split("; ");
var name1 = splitCookie[0].split("=")[1];
<body document.forms[0].firstName.focus();">
First Name <input type="text" name="firstName"><br>
<input type="button" value="cookie" onclick="set();">
<input type="button" value="Get Cook" onclick="getCookie();">
<div id="foo"></div>

12-18-2004, 12:18 PM

Thanx for the sample coding. I can get the out put, but if i close the window and open a new window and goes to the same site instead of accessing the cookie name it displays as t=3. What could be the problem.


12-18-2004, 12:27 PM
The way you are retreiving your cookie is not persistant. When I run your code I don't get the right results each time. One time I will get the correct results, then the next i'll only get a few letters, and so on. How are you setting your cookie? If you try my example into your code im sure it will work.

Willy Duitt
12-18-2004, 04:04 PM

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum