/    Sign up×
Community /Pin to ProfileBookmark

how do i save a variable to a cookie?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaNov 18.2003 — [font=monospace]

<!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>

[/font]

[b][J]ona[/b]
×

Success!

Help @davey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...