Javascript Cookies

When i take the cookie part out i don't get an error. When i add it i do.

I want to set the cookie and read it.

THis only has to work in IE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">

if ReadCookie('LeftNavState') == '' {
      SetCookie( 'LeftNavState', 'none', '1' );

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));

                       function toggleDisplay(id)
                       var elm = document.getElementById(id);
                       if (elm != null)
                       var d =;
              = (d == 'none') ? 'block' : 'none';
                                 if ( == 'block') {
                                 //alert('here 1');
                                       document.getElementById('imgShowHide').src= 'Hide.jpg';
                                 } else {
                                  //alert('here 2');
                                       document.getElementById('imgShowHide').src= 'Show.jpg';
<body >
<form id="form1">
<script language="JavaScript">
if (testValue==ReadCookie('AreCookiesEnabled'))
     document.write('<b>Cookies are currently enabled in your browser.</b>');
else document.write('<b>Cookies are not currently enabled in your browser.</b>');
<br /><br />

<td id="tdLeftNav"><a href="page2.html">Page 2</a></td>
<div onclick="toggleDisplay('tdLeftNav');" style="CURSOR: hand">
<img src="Hide.jpg" border="0" id="imgShowHide" name="imgShowHide" />


Who is Participating?
ZvonkoConnect With a Mentor Systems architectCommented:
if statements need always braces.
This is without braces:
if ReadCookie('LeftNavState') == '' {

Correct is this:
if (ReadCookie('LeftNavState') == '') {

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.