/    Sign up×
Community /Pin to ProfileBookmark

Problems writing a simple coookie

Hi,
Im having problems with a simple problem.
I’m trying to detect whether users have cookies and Javascript enabled from this tutorial on 4 Guys from Rolla ( [url]http://www.aspfaqs.com/webtech/082400-1.shtml[/url] ). I have one page which writes a cookie using Javascript then when the body loads it detects the cookie, if the cookie exists it changes the value of a hidden field in a form. The form should then submit to another page which looks at the value of the hidden field, if it hasnt been changed then either cookies or javascript is disabled or not supported. I cant get it work. Im using internet explorer with javascript and cookies enabled but i cant get the javascript to write the cookie. Im sure its something simple. I was really appreciate it if anyone could point out any obvious reasons why it wouldnt work.

Heres the code for the page with the hidden field and the javascript function to change the hidden field.

<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”1252″%>
<html>
<head>
<script language=”JavaScript”>
<!-
function cc()
{
/* check for a cookie */
if (document.cookie == “”)
{
/* if a cookie is not found – alert user –
change cookieexists field value to false *
/
alert(“COOKIES need to be enabled!”);

/* If the user has Cookies disabled an alert will let him know
that cookies need to be enabled to log on.*/

document.Form1.cookieexists.value =”false”

} else {
/* this sets the value to true and nothing else will happen,
the user will be able to log on*
/
document.Form1.cookieexists.value =”true”
}
}

/* Set a cookie to be sure that one exists.
Note that this is outside the function*
/
document.cookie = ‘killme’ + escape(‘nothing’)
// –>
</script>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>

<body onLoad=”cc()”>
<form action=”check2.asp” method=”post” name=”Form1″ id=”Form1″>
<input type=”hidden” name=”cookieexists” value=”false”><input name=”Submit” type=”submit” value=”Submit”>
</form>
</body>
</html>

Thanks for any advice
Craig

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliSep 03.2003 — here is a pretty simple cookie writing script example.Hope it helps.

http://www.webapplikations.com/pages/html_js/document/SimpleLoginCookieScript.html
×

Success!

Help @craigcsbdon 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 4.29,
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,
)...