brandon079
03-20-2006, 11:37 AM
My site has an image at the top that randomly changes when clicked, What I'm wanting to do is to change certain table's bgcolor when clicked using a second array. I managed to get this working for the background color but thats not what im going for. I also have a style tag that changes the desired tables, the problem is that I cant seem to get the style tag to us a variable instead of a RGB color. You can view the site here (http://r.unkill.org).
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "qwerty/01original.jpg";
images[2] = new Image();
images[2].src = "qwerty/02wizard.jpg";
images[3] = new Image();
images[3].src = "qwerty/03pirate.jpg";
images[4] = new Image();
images[4].src = "qwerty/04stpatty.jpg";
var ccolor = new Array();
ccolor[1] = "2e9f1a";
ccolor[2] = "c17000";
ccolor[3] = "A7734A";
ccolor[4] = "2e9f1a";
function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
newcolor.bgcolor = ccolor[useRand];
//document.bgColor = ccolor[useRand]; //for testing purposes only
}
// End -->
</script>
<style> table#newcolor {background-color: #c17000;}</style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "qwerty/01original.jpg";
images[2] = new Image();
images[2].src = "qwerty/02wizard.jpg";
images[3] = new Image();
images[3].src = "qwerty/03pirate.jpg";
images[4] = new Image();
images[4].src = "qwerty/04stpatty.jpg";
var ccolor = new Array();
ccolor[1] = "2e9f1a";
ccolor[2] = "c17000";
ccolor[3] = "A7734A";
ccolor[4] = "2e9f1a";
function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
newcolor.bgcolor = ccolor[useRand];
//document.bgColor = ccolor[useRand]; //for testing purposes only
}
// End -->
</script>
<style> table#newcolor {background-color: #c17000;}</style>