PDA

View Full Version : computer based training module help



pricecd
04-18-2006, 10:24 PM
For my javascript class we have to create a functional computer based training module. I've finished most of my content, but I'm having a little trouble. There are 5 modules that you can access from the main page. I need to have it so that the cookies keep track of what page your on in each section. If someone were to leave the site and go back into the section they were on it'll start them on the page that were on when they exited the browser. Can anyone offer me a little help? I'm a big newbie when it comes to javascript :(

Twey
04-18-2006, 10:42 PM
I don't usually advise using a pre-built script, but... tried Moodle (http://www.moodle.org/)?

pricecd
04-19-2006, 11:40 PM
here is a little more information:



I know I need two cookies one to keep track of the last page that the user has visited and one to flag whether or not this is the first time they've seen the page this session. Im just having syntax problems. Can someone help me fix my code?

this is the script on the main page:



function setCookies()
{

var cdRom = document.location="cdrom1.html"

document.cookie = "cdRom="+cdRom+";expires=" + expireDate.toGMTString()

document.location="cdrom1.html"

}

this is the script on the first page of one of my sections:


expireDate = new Date()
expireDate.setYear(expireDate.getYear()+1)

function getCookie(Name)
{
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf(search)

if (offset != -1)
{
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

if(getcookie("track")!="")
{
document.location=cdrom1.html
}
else
{
var stringToSplit=cdRom
var aryStrings=stringToSplit.split("=")
document.location=aryStrings
}

alert(document.cookie)

function setCookies()
{

var cdRom = document.location="cdrom2.html"

document.cookie="track"

document.cookie = "cdRom="+cdRom+";expires=" + expireDate.toGMTString()

document.location="cdrom2.html"

}


I'm new to javascript so be gentle :p

Twey
04-20-2006, 08:51 AM
This would be better done server-side, as with all cookie-based systems.