• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

help with javascript?

zimu

Diamond Member
I know i'm doing this totally wrong, i've tried a 100 times but i can't get it! whats wrong with this code?
i want the background to be changed using the form:

<html>
<head>
<title>
Background Color Changer
</title>

<script language="JavaScript">
<!-- Beginning of JavaScript -

function SetBGColor(mycolor) {
document.bgcolor = mycolor;
}
// - End of JavaScript - -->
</script>
</head>
<body>
<form>
Pick a COLOR!

<input type=radio name=choice value="red">Red

<input type=radio name=choice value="blue">Blue

<input type=radio name=choice value="black">Black

<input type=radio name=choice value="white">White

<input type=button value="Change it!"
onClick="javascript:SetBGColor(choice.value);">
</form>
</body>
</html>
 
Try this..

<html>
<head>
<title>
Background Color Changer
</title>

<script language="JavaScript">
<!-- Beginning of JavaScript -

function SetBGColor() {
var j;

for (j=0; j < document.colorForm.choice.length; j++) {
if (document.colorForm.choice[j].checked==true) {
document.bgColor=document.colorForm.choice[j].value
}
}
}
// - End of JavaScript - -->
</script>
</head>
<body>
<form name=colorForm>
Pick a COLOR!

<input type=radio name=choice value="red">Red

<input type=radio name=choice value="blue">Blue

<input type=radio name=choice value="black">Black

<input type=radio name=choice value="white">White

<input type=button value="Change it!"
onClick="javascript:SetBGColor();">

</form>
</body>
</html>
 
<html>
<head>
<title>
Background Color Changer
</title>

<script language="JavaScript">
<!-- Beginning of JavaScript -

function SetBGColor(mycolor) {
body.style.backgroundColor = mycolor;
}
// - End of JavaScript - -->
</script>
</head>
<body>
<form>
Pick a COLOR!

<input type=radio name=choice value="red">Red

<input type=radio name=choice value="blue">Blue

<input type=radio name=choice value="black">Black

<input type=radio name=choice value="white">White

<input type=button value="Change it!"
onChange="javascript:SetBGColor(this.value);">
</form>
</body>
</html>
 
Originally posted by: Shazam
<html>
<head>
<title>
Background Color Changer
</title>

<script language="JavaScript">
<!-- Beginning of JavaScript -

function SetBGColor(mycolor) {
body.style.backgroundColor = mycolor;
}
// - End of JavaScript - -->
</script>
</head>
<body>
<form>
Pick a COLOR!

<input type=radio name=choice value="red">Red

<input type=radio name=choice value="blue">Blue

<input type=radio name=choice value="black">Black

<input type=radio name=choice value="white">White

<input type=button value="Change it!"
onChange="javascript:SetBGColor(this.value);">
</form>
</body>
</html>

That won't work. The variable "choice" is an array. You have to loop thru it to see which one is "checked" and extract that value.
Look at my code above..
 
Back
Top