thread reference:
[url]http://www.webdeveloper.com/forum/showthread.php?s=&threadid=39473&highlight=BakeCookie
Please bear with me, I’m still trying to learn Javascript.
I’ve been trying to figure out the BakeCookie and EatCookie.
I’ve ran several tests and I’m doing something wrong, I can’t seem to find out what, but it is not placing a cookie.
[SIZE=1]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2//EN”>
<html>
<head>
<SCRIPT type=”text/javascript”>
function BakeCookie(name,value) {
var argv=arguments;
var argc=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+”=”+escape(value) +
((expires === null) ? “” : (“; expires=”+expires.toUTCString())) +
((path === null) ? “” : (“; path=”+path)) +
((domain === null) ? “” : (“; domain=”+domain)) +
((secure === true) ? “; secure” : “”);
}
</SCRIPT>
<SCRIPT type=”text/javascript”>
function EatCookie(name) {
var arg=name+”=”;
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 EatCookieVal(j);
}
i=document.cookie.indexOf(” “,i) + 1;
if (i === 0) {break;}
}
}
function EatCookieVal(offset) {
var endstr=document.cookie.indexOf(“;”,offset);
if (endstr == -1) {endstr=document.cookie.length;}
return unescape(document.cookie.substring(offset,endstr));
}
</SCRIPT>
</head>
<body>
<form>
<!– make text box to enter name and store it in a cookie –>
<INPUT name=”cookiestorage01″ type=”text” value=”enter a name” size=”30″><br>
<INPUT name=”cookievalue” type=”text” value=”cookie value” size=”30″>
<INPUT type=”button” value=”Set Cookie” onClick=”BakeCookie(cookiestorage01,cookievalue);”>
</form>
</body>
</html>
The only part of the code that I did was in the Form. The rest of it was copied directly from the BakeCookie/EatCookie code.
I’m not doing so well with the document.write command, I was trying to start with some basics first.