/    Sign up×
Community /Pin to ProfileBookmark

bgcolor changer

I have the following script that I cant quite make work…. you are supposed to be able to choose a color from the drop down menu, click the button and the background should become the chosen color until a new color is chosen, or the page refreashed.

[Code]
<html>
<head>
<title>Color Changer</title>
<Link href=”externalcolorselect.css” rel=”Stylesheet” type=”Text/CSS”>
<script type=”javascript”>
Function getColor(){
var theSelect=document.myForm.color;
var theOption=theSelect.options[theSelect.selectedIndex];
var theColor=theOption.value;
document.body.style.backgroundColor=theColor;
}
</script>
</head>
<body>
<h1>Background Color Changer:</h1>
<h3>Please Select a Color</h3>
<center>
<form name=”myForm”>
<select name=”color”>
<option value=”red”>Red</option>
<option value=”blue”>Blue</option>
<option value=”green”>Green</option>
<option value=”yellow”>Yellow</option>
<option value=”white”>White</option>
document.myForm.color.selectedindex
</select>
</form>
<input type=”button” onclick=”getColor()” value=”Change Background Color” />
</center>
<hr>
<br />

</body>
[/Code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Brandoe85Dec 01.2004 — Function, should be spelt with a lower case 'f', and the script tag should be <script type="[COLOR=red]text/[/COLOR]javascript">
[CODE]
<html>
<head>
<title>Color Changer</title>
<Link href="externalcolorselect.css" rel="Stylesheet" type="Text/CSS">
<script type="text/javascript">
function getColor(){
var theSelect=document.myForm.color;
var theOption=theSelect.options[theSelect.selectedIndex];
var theColor=theOption.value;
document.body.style.backgroundColor=theColor;
}
</script>
</head>
<body>
<h1>Background Color Changer:</h1>
<h3>Please Select a Color</h3>
<center>
<form name="myForm">
<select name="color">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="yellow">Yellow</option>
<option value="white">White</option>
document.myForm.color.selectedindex
</select>
</form>
<input type="button" onclick="getColor()" value="Change Background Color" />
</center>
<hr>
<br />
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@CharlesDec 01.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

</head>

<body>

<div>

<select onchange="document.bgColor = this[this.selectedIndex].value">

<option value="#ff0000">Red</option>

<option value="#0000ff">Blue</option>

<option value="#00ff00">Green</option>

<option value="#ffff000">Yellow</option>

<option value="#ffffff">White</option>

</select>

</div>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@CorngopherauthorDec 01.2004 — Thank you very much. They seem like such small errors but they stopped me just the same ?
Copy linkTweet thisAlerts:
@Brandoe85Dec 01.2004 — You're welcome, sometimes the simplest little things slip by ya.
×

Success!

Help @Corngopher spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...