Hi all, I'm learning JavaScript and have run into a problem. Displaying the contents of a cookie with the code


works fine in Firefox, but in Safari 3.0.4, it just displays an empty alert box. Any quick answers? Any resources that you can point me to? Thanks in advance, and here's the complete code:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>App 8.1</title>

<script type="text/javascript" >
 	function submitForm(form) {
		document.cookie = "userName=" + form.userName.value;
		if(form.userName.value == "") {
			alert("No name was entered.");
			return false;
		else {
			alert("Cookie value is\n" + document.cookie);
			return false;

	Your name here:
	<input type="text" name="userName" value="">
	<input type="button" name="submit" value="Submit!" onClick="submitForm(this.form);">


It may be a difference in the way a particular browser stores cookies.

Read the part about document.cookie on this page. You are missing some important bits and pieces in your cookie creation code. Also it would be interesting to note that the cookie property of the document is not of type string though it normally is treated like one. Taking care of this should most probably solve your issue.