am trying to generate a page-counting cookie that is updated every time someone returns to the site. My code is off I need help. Here are my htm and js files?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--
New Perspectives on Javascript, 2nd Edition
Tutorial 9
Case Problem 1
CycloCrossings Rider Profile
Author:
Date: May 30, 2010
Filename: hangers.htm
Supporting files: chphoto.jpg, chstyles.css, counter.js,
wall.jpg, wall2.jpg
-->
<title>Cliff Hangers Climbing School</title>
<link href="chstyles.css" rel="stylesheet" type="text/css" />
<script src="counter.js" type="text/javascript"></script>
</head>
<body>
<div id="head"><img src="chlogo.jpg" alt="Cliff Hangers" /></div>
<div id="pageContent">
<div id="leftCol">
<ul>
<li><a href="#">Home Page</a></li>
<li><a href="#">Our Philosophy</a></li>
<li><a href="#">Climbing Lessons</a></li>
<li><a href="#">Tours</a></li>
<ul>
<li><a href="#">Petit Grepon</a></li>
<li><a href="#">Lumpy Ridge</a></li>
<li><a href="#">North Face</a></li>
<li><a href="#">Kiener's</a></li>
<li><a href="#">The Diamond</a></li>
<li><a href="#">Eldorado</a></li>
</ul>
<li><a href="#">Staff</a></li>
</ul>
</div>
<div id="rightCol">
<div style="float:right; margin: 0px 0px 10px 10px">
<img src="chphoto.jpg" alt="" />
</div>
<p id="firstp">
Welcome to one of America's best climbing schools located in one of
America's best climbing areas, the Colorado Rockies. Nowhere else in
America is there such a rich variety of technically
challenging rock, ice, and high alpine routes. The area presents the
climber with a choice of multiple-pitch climbs and big wall routes. Whether
you are here to enjoy the spectacular scenery or to train for an expedition,
you can choose no better place than the Colorado Front Range.</p>
<p>And no one else brings the experience of the Rockies to you better than
<span style="font-weight: bold; color: brown">Cliff Hangers Climbing
School</span>. Whether you are a beginner, itching to learn the skill and art of
climbing, or an experienced mountaineer looking for guides to take you on
some of Rocky Mountain National Park's more challenging climbs, consider us
your gateway to the mountains.</p>
<p>We provide five levels of instruction, ranging from Beginner to Advanced,
including lessons in aid and ice climbing. Members of our experienced staff
have led expeditions in Mexico, Nepal, and Pakistan. All have intimate
knowledge of the Colorado Rockies and know the best places to go
to help you experience the wonder and beauty of the area.</p>
<p>So contact us today, and start climbing tomorrow!</p>
</div>
</div>
</body>
</html>
------------------------------------------------------
/*
New Perspectives on Javascript, 2nd Edition
Tutorial 9
Case Problem 1
Author:
Date: May 30, 2010
Filename: counter.js
Functions List:
addEvent(object, evName, fnName, cap)
Adds an event handler to object where object is the object
reference, evName is the name of the event, fnName is the
reference to the function, and cap specifies the
capture phase.
writeDateString(dateObj)
Returns the date contained in the dateObj date object as
a text string in the format mmm. dd, yyyy
storeCookie(cName, cValue, expDate, cPath, cDomain, cSecure)
Stores a cookie named cName with value cValue. Optional parameters
expDate, cPath, cDomain, and cSecure set the expiry date,
path, doman, and secure flag
getCookie(cName)
Returns the value of cookie, cName.
setCounter()
Retrieves and updates the date last visited and page counter
cookies and displays them on the Web page along with the
date last modified.
*/
setCounter()
function addEvent(object, evName, fnName, cap) {
if (object.attachEvent)
object.attachEvent("on" + evName, fnName) ;
else if (object.addEventListener)
object.addEventListener(evName, fnName, cap) ;
}
function writeDateString(dateObj) {
var monthName = new Array("Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec");
var thisMonth = dateObj.getMonth() ;
var thisYear = dateObj.getFullYear() ;
return monthName[thisMonth] + " " + dateObj.getDate() + ", " + thisYear;
}
function setCookie(cName, cValue, expDate, cPath, cDomain, cSecure) {
if (cName && cValue != "") {
var cString = cName + "=" + escape(cValue) ;
cString += (expDate ? ";expires=" + expDate.toGMTString(): "") ;
cString += (cPath ? ";path=" + cPath : "");
cString += (cDomain ? ";domain=" + cDomain : "") ;
cString += (cSecure ? ";secure" : "");
document.cookie = cString;
}
}
function getCookie(cName) {
if (document.cookie) {
var cookies = document.cookie.split("; ") ;
for (var i = 0; i < cookies.length; i++) {
if (cookies[i].split("=")[0] == cName) {
return unescape(cookies[i].split("=")[1]) ;
}
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1) ;
// This cookie is history
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
<div id="pageFooter">
<span>Visit Number: pageCount</span>
<span>lastVisit</span>
<span>Last Update: pageUpdate</span>
</div>
}
/* Add new code below */
function writeCookie(cName, cValue, expDate) {
if (cName && cValue != "") {
var cString = cName + "=" + escape(cValue);
if (expDate) cString += ";expires=" + expDate.toGMTString() ;
if (cPath) cString += ";path=" + cPath;
if (cDomain) cString += ";domain=" + cDomain ;
if (cSecure) cString += ";secure";
document.cookie = cString;
}
}
function retrieveCookie(cName) {
if (document.cookie) {
var cookiesArray = document.cookie.split ("; ") ;
for (var i = 0; i < cookiesArray.length; i++) {
if (cookiesArray[i].split("=")[0] == cName) {
return unescape(cookiesArray[i].split("=")[1] ) ;
}
}
function deleteCookie(cName) {
if (document.cookie} {
var cookiesArray = document.cookie.split ("; ") ;
for (var i = 0; i < cookiesArray.length; i++) {
if (cookiesArray[i].split("=")[0] = = cName) {
document.cookie = cName + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
}
}
function writeCookie(cName, fName, fValue, expDate, cPath, cDomain, cSecure) {
if (cName && Name && fValue != "") {
// Create the subKey
var subKey = fName + "=" + escape (fvalue) ;
}
}
function retrieveMCookie (cName, fName) {
if (document.cookie) {
// Retrieve the cookie value
// Retrieve the field value within the cookie
}
}
if (retrieveCookie ("lastVisit") = = null) lastVisit = "First time"
else lastVisit = retrieveCookie ("lastVisit") ;
var today = new Date () ;
var currentVisit = writeDateString (today) ;
expire = new Date () ;
expire.setMonth (expire.getMonth () + 6) ;
writeCookie ("lastVisit", currentVisit, expire) ;
}