Click to See Complete Forum and Search --> : Background Image change
aommaster
01-07-2004, 06:49 AM
I want to create a hyperlink so that the background of my website change. I have looked for different codes but they do not do what i want.
I want it so that if the link is pressed, it changes to yellow, and if it is pressed AGAIN, it changes back to the original colour
Thanx
clairec666
01-07-2004, 06:54 AM
<html>
<head>
<title>
Change Background Colour
</title>
<script type="text/javascript">
function changeblack() {
document.bgColor="black";
}
function changeblue() {
document.bgColor="blue";
}
function changered() {
document.bgColor="red";
}
</script>
</head>
<body>
<input type="button" value="Red"onclick="changered()">
<input type="button" value="Blue"onclick="changeblue()">
<input type="button" value="Black"onclick="changeblack()">
</body>
</html>
Here's a version with buttons............ edit it as you wish, or ask me for more help etc. :D
aommaster
01-07-2004, 06:57 AM
Well, the coding works, but it was not what i was looking for :( . You know what a hyperlink is right? Well, i want it to be in that form, and when pressed once, i tgoes to yellow, and then when pressed again, changes back to the original colour (black)
TheBearMay
01-07-2004, 07:19 AM
Slight variation from what Claire was showing you...
var colorArr=["black", "blue", "red", "yellow"];
var colorInx=0;
function bgChange(){
document.bgColor=colorArr[colorInx];
colorInx++;
if (colorInx>colorArr.length-1) colorInx=0;
}
....
<a href=# onclick="bgChange();">Change Color</a>
clairec666
01-07-2004, 07:21 AM
Cheers for that, I couldn't be bothered to do it myself :D I'd taken it from a version I wrote when I was just starting with JavaScript, so I hadn't quite got the heng of it by then......... hence the seperate functions...........
aommaster
01-07-2004, 07:22 AM
Yeah, but where does it go? When i paste in in the body there is some javascode and then a link!!!
clairec666
01-07-2004, 07:24 AM
<script type="text/javascript">
var colorArr=["black", "blue", "red", "yellow"];
var colorInx=0;
function bgChange(){
document.bgColor=colorArr[colorInx];
colorInx++;
if (colorInx>colorArr.length-1) colorInx=0;
}
</script>
<a href=# onclick="bgChange();">Change Color</a>
TheBearMay
01-07-2004, 07:25 AM
<html>
<head>
<script type="text/javascript">
var colorArr=["black", "blue", "red", "yellow"];
var colorInx=0;
function bgChange(){
document.bgColor=colorArr[colorInx];
colorInx++;
if (colorInx>colorArr.length-1) colorInx=0;
}
</script
</head>
<body>
<a href=# onclick="bgChange();">Change Color</a>
</body>
</html>
aommaster
01-07-2004, 07:27 AM
THANKS ALOT!!! Exactly what i was looking for. I spent an hour looking for it. Thanx again guys for helping me
clairec666
01-07-2004, 07:28 AM
The original question said that it should swap between original colour + alternative colour, so to do that you would just take out two of the colours in the array.
aommaster
01-07-2004, 07:29 AM
Yeah, i already did that to make sure. At least i know that i can put a sequence of colours in the code. Thanx man!