Code:
<html>
<head>
<script type="text/javascript" src="cookie.js"></script>
<script type="text/javascript">
var textColor;
var backColor;
function greetUser() {
if (navigator.cookieEnabled)
textColor = readCookie("your_textColor");
backColor = readCookie("your_backColor");
if (textColor)
alert("Hello the color " + textColor + " has been changed to the text.");
document.getElementById('main').style.color= textColor;
if(backColor)
alert("Hello the color " + backColor + " has been changed to the background color.");
document.getElementById('main').style.backgroundColor= backColor;
else
alert('Hello, I do not remember your information.');
}
function loadInfo() {
if (textColor ) {
alert("The text color " + textColor + " has been loaded. Thank you.");
if (backColor)
alert("The background color " + backColor + " has been loaded. Thank you.");
}
else {
textColor = prompt("What is your text color?", "Enter your color here.");
backColor = prompt("What is your background color?", "Enter your color here.");
if (textColor) {
alert("I see your text color is " + textColor + ". It has been changed.");
document.getElementById('main').style.color= textColor;
}
if(backColor) {
alert("I see your background color is " + backColor + ". It has been changed.");
document.getElementById('main').style.backgroundColor= backColor;
}
if (navigator.cookieEnabled) {
writeCookie("your_textColor", textColor, 24 * 7);
writeCookie("your_backColor", backColor, 24 * 7);
}
else {
alert("Cookies aren't supported/enabled in your browser, which means I won't remember you later. I'm sorry.");
}
}
}
document.write("The current text color is " + textColor + ".");
document.write("The current background color is " + backColor + ".");
</script>
</head>
<body onload="greetUser(); loadInfo()" id="main">
</body>
</html>
*******************************************************************
cookie.js
------------------
function writeCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}u
function readCookie(name) {
var searchName = name + "=";
var cookies = document.cookie.split(';');
for(var i=0; i < cookies.length; i++) {
var c = cookies[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(searchName) == 0)
return c.substring(searchName.length, c.length);
}
return null;
}
function eraseCookie(name) {
writeCookie(name, "", -1);
}
Basically I'm trying to make it so whatever the user puts in the alert box can be taken and used as a color towards text/background. I can't seem to get it though.. help? :x I'm trying to use "document.getElementById('main').style.color= textColor;" etc as you can see, but that doesn't work. I'm pretty bad at this so any help is appreciated.








