Click to See Complete Forum and Search --> : bg color switch


PunkSktBrdr01
08-06-2003, 10:19 PM
I made this little page to test a background color switch, but I can't get it too work. I searched through a bunch of old threads, but I haven't been able to solve this. Here's my code so far:


<html>
<head>
<title>test page</title>
<script language="JavaScript">
function bgSwitch(color) {
document.background = color;
}
</script>
<style type="text/css">
body {
background:#000000;
color:#000000;
}
input {
cursor:hand;
}
</style>
</head>
<body>
<center>
<br>
<form name="switch_form">
<input type="button" name="switch_on" value="turn on the lights" onClick="bgSwitch('#FFFF00');">
<br>
<input type="button" name="switch_off" value="turn off the lights" onClick="bgSwitch('#000000');">
</form>
<br><br>
Can you see?
</center>
</body>
</html>


I tested this code in both MSIE 6 and Opera 7 on Windows ME. Thanks!

kdcgrohl
08-06-2003, 10:27 PM
try this...
<input type=button value="Lights Off" onClick="document.bgColor='000000';">
<input type=button value="Lights On" onClick="document.bgColor='FFFFFF';">

pyro
08-06-2003, 10:30 PM
This will probably work quite a bit better for you, and will fix some of the errors you had on your page (no doctype, no charset, no type attribute specified for the script tag, etc). The line in bold is what was needed to fix the immediate problem, though.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function bgSwitch(color) {
document.body.style.backgroundColor = color;
}
</script>
<style type="text/css">
body {
background: #000000;
color: #000000;
}
input {
cursor: pointer;
}
</style>
</head>
<body>
<div style="text-align: center;">
<form name="switch_form">
<p><input type="button" name="switch_on" value="turn on the lights" onClick="bgSwitch('#FFFF00');">
<br>
<input type="button" name="switch_off" value="turn off the lights" onClick="bgSwitch('#000000');">
</p>
</form>
<p>Can you see?</p>
</div>
</body>
</html>

PunkSktBrdr01
08-06-2003, 10:37 PM
I'll try that. Thanks!

PunkSktBrdr01
08-06-2003, 10:41 PM
Pyro, your code works great! Thanks so much.

pyro
08-06-2003, 10:49 PM
The code I posted, however, is IE only... I'm seeing if I can fix that quick... ;)