/    Sign up×
Community /Pin to ProfileBookmark

Cookie needs help.

I have a web page that sets a variable into a cookie and then another page then loads the cookie data and places it in random places on the page. I’m using it right now to hold the name of the particular person visiting the page. I want to use two different variables instead of just one however, so as to hold a number for another script I have. Anyone got ideas?

This is the code that sets the cookie:

[CODE]expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+12)
visitid = “”
if (document.cookie != “”) {
visitid = document.cookie.split(“=”)[1]}
function setCookie() {
visitid = document.myForm.nameField.value
document.cookie = “visitid=”+visitid + expireDate.toGMTString()
}[/CODE]

The form named above as “myForm” is the textbox that the user puts their name into.

Then there’s the code that reads it:

[CODE]if (document.cookie !=””) {
var username = (document.cookie.split(“=”)[1])
}[/CODE]

and then all over the page i just put this in:

[CODE]document.write(username)[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@AmazingAntauthorNov 29.2005 — ok, how would i edit my coding i have in my last post to give the cookie a name so that I can just create two cookies?
×

Success!

Help @AmazingAnt 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.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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