Hey,
I have to make a page that displays a form with 2 fields for name and family name and a choice of colors to set as the background if it’s the first time you open the page. If you’ve been on that page before the previous information must be hidden and I have to display a msg saying “Bonjour, Name FamiliyName, good morning(if it’s before noon) good afternoon (if it’s before 6pm) and good evening(if it’s later than 6pm)” and the color that the user chose on his previous visit must be set for the background color.
I’ve spent the passed couple days searching on this but I don’t understand javascript and cookies enough to use what I see and add it to my script to make it work. So I copied the script off a tutorial site and I’m trying to modify it to do what I need it to but I don’t realy know what I’m doing lol.
If someone could take a look at what I have so far and point me in the right direction or tell me what I need to change/remove or add, that would be greatly appreciated.
Instead of having the prompt box if there is no cookie, that’s where I need the form to show, asking first name,familyname and fav color.
So here is what I have so far:
[CODE]
<html>
<head>
<script language=”javascript”>
function daytime()
{
var now = newDate()
var hour = now.getHours();
if (hour<12)
{
timemsg=”bonne avant-midi.”
}
else if (hour<18)
{
timemsg=”bonne après-midi.”
}
else (hour>=18)
{
timemsg=”bonsoir.”
}
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + “=”);
if (c_start!=-1)
{
c_start=c_start + c_name.length+1 ;
c_end=document.cookie.indexOf(“;”,c_start);
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end));
}
}
return “”
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ “=” +escape(value)+((expiredays==null) ? “” : “; expires=”+exdate.toGMTString());
}
function checkCookie()
{
username=getCookie(‘username’);
if (username!=null && username!=””)
{
document.write(“Bienvenue, “+username+famname+”, “+timemsg);
}
else
{
username=prompt(‘Please enter your name:’,””);
if (username!=null && username!=””)
{
setCookie(‘username’,username,365);
}
}
}
</script>
</head>
<body onLoad=”checkCookie()”>
</body>
</html>