Computer problems,Computer help
*AX SOFT>>>Programming & Design

Javascript- can someone write this code for me?


Contain a drop down using the select tag with the following:
a. Title: Red Value: #FF0000
b. Title: Green Value: #00FF00
c. Title: Blue Value: #0000FF
d. Title: Black Value: #000000
The drop down menu should have the name "colors" and should have the event onChange call a method named changeColor(this.form) to pass the form value to the function.

Create the function changeColor. The function should identify the selected index, get the corresponding hexadecimal value, and change the background color of the web page to the given color. To change the color of the web page, assign the following object a hexadecimal color value: document.body.bgcolor.


This is an assignment for an HTML class I am taking, and these are the instructions from the professor - however, I cannot figure out how to do this.
Any help is greatly appreciated.
Thanks.

document.body.bgcolor is an outmoded usage - should be document.body.style.backgroundColor. Also, providing "White" as the first value (default) ensures that a change event will be fired for the selection of any other color; if "Red" was the first value, and the user picked it on initial entry to the page, no change event would fire.

<head>
<!--
No matter which you select
as "best answer" - pick one.
-->
<script>
function changeColor(form) {
var select = form.elements[0];
var choice = select.selectedIndex;
var color = select[choice].value;
var s = document.body.style;
s.backgroundColor = color;
}
</script>

</head>
<body>
<form>
<select
onchange="changeColor(this.form);">
<option value="#FFFFFF"
>White (default)</option>
<option value="#FF0000"
>Red</option>
<option value="#00FF00"
>Green</option>
<option value="#0000FF"
>Blue</option>
<option value="#000000"
>Black</option>
</select>
</form>
</body>
</html>

<html>

actually i have visual basic but i think ican help you i use this in it ""

when you press a:
document.body.bgcolor = a.title

when you press b:
document.body.bgcolor = b.title

when you press c:
document.body.bgcolor = c.title

when you press d:
document.body.bgcolor = d.title

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • How do you load textures on Adobe Photoshop 7?

    You can create your own in Photoshop or download them from websites. They can be jpeg files or even psd files. To use them in Photoshop, they need to be copied to the following folder: C:\Pro...

  • My PHP form isn't sending to my email?

    thats your entire script? email me..... nothing seems right here at all....also try changing the file name to config.inc.php.....if that dont work email me with more details silent...

  • T -SQL tutorial sites?

    Here are a few sites to look over: ...

  • Have you ever use Transperent note Book?

    yes i heard about it.

    ...
  • Can anyone with programming, specifically C++, experience help me? (little needed) What's wrong in this script

    int main(void) ( <===== problem That parenthesis needs to be changed to a "{" instead ....called a "left curly brace" .... it is next to the "P" key Change...

  • Is the C++ for dummies book a good way to start learning C++?

    I own the book and had read much of it as a 14-year-old. I felt like it had an awkward pace. It starts off by saying a lot of stuff I didn't understand (like the history of GNU C++, how to p...

  • What is the top current web development language?

    Edited: 7:09 p.m. EST The biggies out there are ASP.NET, followed by JSP and PhP. ASP.NET is used everywhere - JSP tends to be used by people who like open source as is PhP. (If you go with Ph...

  • I need tutorial ideas for a hypercam?

    Please look at here, ...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster