Click to See Complete Forum and Search --> : wondering if I am doing this right....


2 peachy
05-19-2003, 11:07 PM
ok here is what I have done so far... am I anywhere close to what it should be ?
I want my name to be the value of the cookie and for it to expire in thirty days , and renew the 30 day expiration time each time I visit the page???
am I going in the right direction here ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function getCookie(Irene)
{
if (document.cookie.length > 0)
{

begin = document.cookie.indexOf(Irene+"=");
if (begin != -1)
{

begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;

}
function setCookie(NameOfCookie, value, expiredays)
{

var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (30 * 24 * 3600 * 1000));

document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}


</script>
</head>

<body>

</body>
</html>

2 peachy
05-19-2003, 11:42 PM
grrrrrrrrr... of all the things I have been trying to learn... this it the one that I completely do not understand !!!!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "Irene";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "Irene" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "Irene" + cval + "; expires=" + exp.toGMTString();
}

var name = GetCookie('Irene');
}
window.location.href = url;
}
// End -->
</script>

</head>

<body>
<center>
<form>
<table><tr><td>
Please enter your name:<br>
<br>
<input type=textbox name="Irene" onClick="SetCookie('name', this.name, exp);"><br>


</td></tr>
</table>
</form>
</center>

</body>
</html>

what am I doing wrong here...

Jona
05-19-2003, 11:47 PM
I don't quite have the time to look at it tonight, unfortunately--SAT tests and all... Anyhow, I'd suggest you add an alert(document.cookie); to your JavaScript code for debugging. I always use alerts to get values of elements/properties of elements, because it helps me make sure I know I'm right and also to make sure I'm doing it right.

2 peachy
05-19-2003, 11:49 PM
hmmm.... not sure I know how to do that...

2 peachy
05-19-2003, 11:51 PM
ooooooooops... forgot to say Good Luck with SAT tests

smiles... I am sure you will do well.

Jona
05-19-2003, 11:53 PM
I'm sure I'll do well, too. I normally get at least 95%. Two years ago I got 99%... Talk to ya later.

Jona

P.S. Just add alert(document.cookie); before any of your JavaScript code and it will give your cookie's name, value, etc.

2 peachy
05-20-2003, 12:20 AM
Help, Help, Help...
I am really trying to get it.... I dont expect anyone to merely write it for me.... the cookie thing confuses me...
I have done this about 20 times now and still cant get it to work !!!
what am I doing wrong ?



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + <-- save cookie value
"; expires=" + expires.toGMTString() + "; path=/"; <-- set expiration date
} and universal

var expdate = new Date ();
expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 30)); <-- set 30 day expiration
setCookie ("_name", "Irene", expdate);

function getCookie (name) {
var dcookie = document.cookie;
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(" ", cbegin) + 1;
if (cbegin == 0) break;
}
return null;
}
document.write
alert(getCookie("_name"));




// End -->
</script>

</head>

<body>


</body>
</html>

2 peachy
05-20-2003, 12:50 AM
ok... this thing is somewhat working... but....
this is what I get in popup... cookie Value:nettech1=Irene%603%601053407599383;
Irene=Irene%601%601053388201508; VisitorName=Irene;WWHCount=2;
WWhenH=1053407638352

what am I doing wrong ?
I only want it to say....
Cookie Value=Irene
Expiration Date = 30 days from...whatever date it is that I visited


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Example</title>

<script>
function SetCookie()
{
// get the encoded version of the text box's value
var name = Irene;

// days until expirations
var days = eval(document.myform.expiration.value )

// current date and time
var Now = new Date();

// calculate expiration date in milliseconds
// Now represents the expiration date after calculation
Now.setTime (Now.getTime() + (30 * 24 * 60 * 60 * 1000));
alert ("This cookie will self destruct on\n" + Now);

// create expiration date in days
var cexpire = Now.toGMTString();

// write the cookie value
document.cookie = "MyCookie=" + Irene + "; expires=" + cexpire;

}

function ShowCookie()
{
// get all cookies for this document
var mycookie = document.cookie;

// create message for display
var msg = "cookie Value: " + mycookie;


// display message
alert (msg);
}
</script>

</head>

<body>
<form name="myform">
<input type="button" value="Make Cookie" onClick="SetCookie()">
<input type="button" value="Show Cookie" onClick="ShowCookie()">

</form>
</body>
</html>

2 peachy
05-20-2003, 06:34 AM
ok... got it working now.. just have one question...
I really dont want the text boxes on the page... but everytime
I get rid of them... it doesnt work the same way...
got any suggestions ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Example</title>
<script>

function SetCookie() {

// get cookie value

var cvalue = "Irene"; //escape(document.myform.CookieValue.value);

// days until expirations
var days = "30"; eval(document.myform.expiration.value )

// current date and time
var Now = new Date();

// calculate expiration date in milliseconds
// Now represents the expiration date after calculation

Now.setTime (Now.getTime() + (days * 24 * 60 * 60 * 1000));
alert ("Cookie Value = Irene .\nThis cookie will expire on\n" + Now);

// create expiration date in days

var cexpire = Now.toGMTString();

// write the cookie value

document.cookie = "MyCookie=" + cvalue + "\nExpires=" + cexpire;

//expires=" + cexpire;
//document.cookie = "\nExpires=" + cexpire + ";
}

function ShowCookie() {
// get all cookies for this document
var mycookie = document.cookie;

// create message for display
var msg = "Unescaped version: " + mycookie;

msg += "\nEscaped version: " + unescape(mycookie);

//msg += "\nDate: " + mycookie;

// display message
alert (msg);
}

</script>

</head>
<body>
<form name="myform">
<p>Cookie Value
<input name="CookieValue" type="text" value="Irene" size=15>
<input name="button" type="button" onClick="SetCookie()" value="Make Cookie">
Expiration Date
<input name="expiration" type="text" value="cexpire" size=15>
<input name="button2" type="button" onClick="ShowCookie()" value="Show Cookie">
</p>
<p>&nbsp; </p>
</form>
</body>
</html>

2 peachy
05-20-2003, 11:38 AM
my buttons give escape and unescape versions,
how can I make so I have that information in popups so I can get rid of the text boxes ?

Jona
05-20-2003, 02:29 PM
Not entirely sure what you mean by that.... Could you explain that better please? Thanks. ;)

2 peachy
05-20-2003, 02:53 PM
When you click on make cookie button, you get a popup that says
Cookie Value = Irene
This cookie will expire on
Thu, June 19 12:43:45 PDT 2003


When you click on get cookie
get
Unescaped Version
which is the actual cookie information I am guessing

What I cant figure out is,
I have the Cookie Value set
and the Expiration set in the code

so why do I have to have the text boxes on the page

I would like to be able to click make cookie button and get that popup
and click on the get cookie information and get the Unescaped Version in an alert popup.

but every time I try to take the text boxes off, I only get the unescaped version.


I will attach my html page so you can see what is happening

Jona
05-20-2003, 03:05 PM
Tell me if this is what you want. Notice the changes in the code....

2 peachy
05-20-2003, 03:12 PM
Closer,but make cookie is still displaying some of the same things that get cookie displays...
I think my understanding ... is... and I am not too sure about this...
make cookie is the escape version
and get cookie is the unescape version

right now... make cookie looks sort of like a mixture of the two

Jona
05-20-2003, 03:17 PM
I'm quite not understanding you as well as I thought, then.

2 peachy
05-20-2003, 03:19 PM
will send you a screen shot of both ways
brb

2 peachy
05-20-2003, 03:46 PM
ok here it is...

Jona
05-20-2003, 03:54 PM
OK, your computer already has a cookie stored on it. Go to C:\WINDOWS\Cookies and find one that is something like, "C__yourFolder_cookie" or something like that. Delete it and retry the function I sent you. Make sure you delete all cookies starting with "C."

2 peachy
05-20-2003, 04:09 PM
Thankyou so much for your help

Jona
05-20-2003, 04:19 PM
Sure thing. ;)