I'm beginning to think that I don't have the eyes for this. Chrome's JS console is telling me that on line 28 "setCookie is not defined". What does this mean? I've looked at the function portion and it looked the same as my book but I have missed punctuation/spelling before. Thanks again whoever answers.

Jake

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Personal Preferences</title>


<script type="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS

function setCookie() {
	var expiresDate = new Date();
	expiresDate.setFullYear(expiresDate.getFullYear() + 1);
	document.cookie = encodeURI("user_name=" + document.forms[0].user_name.value) + "; expires=" + expiresDate.toUTCString();
	document.cookie = encodeURI("user_color=" + document.forms[0].user_color.value) + "; expires=" + expiresDate.toUTCString();
	window.alert("Your name and favorite color have been saved in a cookie.");
}

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>

<form action="">
<p>Name: <input type="text" name="user_name" /><br />
Favorite color: <input type="text" name="user_color" /></p>
<p><input type="button" value="Set Cookie" 
	onclick="setCookie();" /></p>
</form>

</body>
</html>

Recommended Answers

All 4 Replies

your script should be type="text/javascript"

Ok, I tried it as "text/javascript" and it worked of course. My question now is why does my book say to declare the script as "Javascript"? I went back and double checked and it definitely reads that way but doesn't say why. Typo or what?

It could work only on IE, but on certain browsers, it doesn't. The type you give 'text' is the most standard for any browser to understand. The same goes with css (text/css).

Ok. My book may be a bit outdated on some things I'm learning. It's copyright date is 2004...Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.