Ok. I have the fixed function. And as said before, I have done lots of research on cookies, and have tried just about every algorithm in the book, and to no avail.
Here's the new code, the only prob is I need to use an array and select box, so depending on what is selected, it will change and save the background using that image, and because it is saved, depending on what image was used, will display that pic using a cookie.
Here's the code:
Ok. I have 1 more small question. Then this is complete
How do I use an array and an if function to tell thefinal variable which picture to display depending on what is selected, and save the selected image value to the cookie using saveImage() ?
heres the code:
<script>
var thediv = "mydiv";
var thedefault = "default.jpg";
var theimg = "myimg.gif";
var num = 0;
var thefinal = [];
thefinal[0] = thedefault;
thefinal[1] = theimg;
var thecolor = "blue";
function menu(){
num++;
document.write('<form name="theform">\n'
+'<select name="favSelect" onchange="getDivBG(thediv, thefinal`);">\n'
+' <option selected="true" value="">--choose--</option>\n'
+' <option value='+thefinal[num]+'>Default</option>\n'
+' <option value='+thefinal[num]+'>My Image</option>\n'
+' </select>\n'
+'</form>\n');
for(var x=1;x<=document.forms.theform.favSelect.length;x++){
if(document.forms.theform.favSelect.selected != ""){
saveImage(thediv, thefinal[x]);
}
}
if(document.forms.theform.favSelect.selected){
alert(thefinal[num]);
}
}
var expDays = 365;
var exp = new Date();
var favImage = "";
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function saveImage(thediv, pic)
{
var favImage = pic;
if ( favImage == "" ) return;
SetCookie('image', favImage, exp);
getDivBG(favImage);
}
function savetheColor(thediv, thecolor)
{
var favColor = color;
SetCookie('image', favColor, exp);
document.body.style.backgroundColor = favColor;
}
function GetCookie(thename)
{
var cookies = document.cookie.split(/; /g);
var arg = thename + "=";
for ( var c = 0; c < cookies.length; ++c )
{
var ck = cookies[c];
if ( ck.indexOf(arg) == 0 )
{
var temp = ck.split(/=/);
return unescape(temp[1]);
}
}
return "";
}
function SetCookie (thename, thevalue)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = thename + "=" + escape (thevalue) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (thename)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (thename);
document.cookie = thename + "=" + cval + "; expires=" + exp.toGMTString();
}
function getBodyBGColor()
{
document.body.style.bgColor="url('" + GetCookie("color") + "')";
}
function getBodyBG()
{
document.body.style.backgroundImage="url('" + GetCookie("image") + "')";
}
function getDivBGColor(thediv, thecolor)
{
if ( thecolor != "")
document.getElementById(thediv).style.bgColor="url('" + thecolor + "')";
}
function getDivBG(thediv, pic)
{
if ( pic != "")
document.getElementById(thediv).style.backgroundImage="url('" + pic + "')";
if(document.forms.theform.favSelect.value != "") alert(document.forms.theform.favSelect.value);
document.getElementById(thediv).style.backgroundPosition="Center";
}
</script>
<body onload="getDivBG(thediv, theimg);">
<form name="theform">
<div id = "mydiv" style="width: 400; height: 250;">My Div</div><script>menu();</script>
</form></body>
Thanks again for all your support!
~SI~