Click to See Complete Forum and Search --> : cookies


davey
11-17-2003, 06:45 PM
how do i save a variable to a cookie?

Jona
11-17-2003, 07:08 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html LANG="EN">
<head><title>Fun with Cookies</title>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html charset=us-ascii">
<meta NAME="Content-Script-Type" CONTENT="text/javascript">
<script TYPE="text/javascript">
<!--
cookie_name = "favColor"; // Set a global variable called, "cookie_name" and set it to the string "favColor."
var YourColor; // Set a global variable named "YourColor"
function setCookie(){ // Start the function called, "setCookie."
YourColor=document.cookieForm.cookieBox.value; // Set the variable "YourColor" to the value of the cookieBox.
document.cookie=cookie_name+"="+YourColor+"; expires=Monday, 04-Apr-2004 05:00:00 GMT"; // Set the cookie. The name of the cookie is equal to the variable, "cookie_name," the value of it is the value of the variable, "YourColor," and the cookie expires on Monday, the fourth of April in the year 2004 at 5:00 GMT.
} // End the function, "setCookie."
//-->
</SCRIPT>
</head>
<body>
<p><h1>Fun with Cookies</h1></p>

<form ACTION="" NAME="cookieForm" ONSUBMIT="return false;">
<div>
<p><input TYPE="text" NAME="cookieBox"></p>
<p><input TYPE="button" ONCLICK="setCookie();"></p>
</div></form>
</body></html>


[J]ona