
May 5th, 2004, 01:21 PM
|
|
Registered User
|
|
Join Date: May 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Help with keeping cookies please.
Hello everyone. I have a script that works fine. The only problem is that the cookies do not stay. The user picks a color, and then the background color changes. When the user comes back to the page, it is supposed to keep that color, but does not. Is there a function I can add to do this, or modify what I already have? I would like to keep the layout as
I have it if possible with using the button.Thanks for the help! Norman.
Code:
<script>
function setCookie()
{
var expiresDate = new Date();
expiresDate.setFullYear(expiresDate.getFullYear() + 1);
document.cookie = encodeURI("setCookie="
+ document.colorchoice.selection.value)+ "; expires = "+ expiresDate.
toUTCString();
alert("Your background color has been saved for your next visit to this page");
}
function colorit() {
var Color = parseInt(document.colorchoice.selection.selectedIn dex)
changeColor(Color)
}
var colorlist = new Array("red","blue","yellow")
function changeColor(color) {
document.bgColor = colorlist[color]
document.colorchoice.value = colorlist[color]
}
</script>
</head>
<body>
<form name="colorchoice">
<p> <h2>Click button to pick color.</h2></p>
<SELECT NAME="selection" value="selectedIndex">
<OPTION>Red
<OPTION>Blue
<OPTION>Yellow
</SELECT>
<INPUT TYPE="button" NAME="Change_Color" VALUE="Change Color" onClick="colorit();
setCookie();"></form>
</body>
</html>
|