473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Changing Background Color

Hi All,
I am creating a simple website using JavaScript.
Basically, it consists of a text input. Then, when you click the button, the background color changes to the color you typed (assuming you typed a legal color)

Here is what I have already... I can't figure out what is wrong with my code:

<head>
<title>Just for Fun</title>
<script language="JavaScript" type="text/javascript">
<!--
function changeColor() {
document.bgcolor = document.color.value;
}
//-->
</script>
</head>

<body>
<h1>Change Color</h1>
<table>
<tr valign="top"><td>
New Color:<input name="color" type="text" size="15" /></td>
<td><input type="button" value="Change" onclick="changeColor();" />
</body>
</html>
Nov 15 '06 #1
2 3825
vee10
141 100+
hi,

i think this is solution for the problem

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title>Just for Fun</title>
  5. <script language="JavaScript" type="text/javascript">
  6. <!--
  7. function changeColor() {
  8. alert(document.form1.color.value);
  9. document.body.style.backgroundColor=document.form1.color.value;
  10.  
  11. }
  12. //-->
  13. </script>
  14. </head>
  15.  
  16. <body>
  17. <h1>Change Color</h1>
  18. <table>
  19. <tr valign="top"><td>
  20. <form name="form1">
  21. New Color:<input name="color" type="text" size="15" /></td>
  22. <td><input type="button" value="Change" onclick="changeColor();" />
  23. </form>
  24. </body>
  25. </html>
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  






































Hi All,
I am creating a simple website using JavaScript.
Basically, it consists of a text input. Then, when you click the button, the background color changes to the color you typed (assuming you typed a legal color)

Here is what I have already... I can't figure out what is wrong with my code:

<head>
<title>Just for Fun</title>
<script language="JavaScript" type="text/javascript">
<!--
function changeColor() {
document.bgcolor = document.color.value;
}
//-->
</script>
</head>

<body>
<h1>Change Color</h1>
<table>
<tr valign="top"><td>
New Color:<input name="color" type="text" size="15" /></td>
<td><input type="button" value="Change" onclick="changeColor();" />
</body>
</html>
Nov 15 '06 #2
Hi,

I have checked the code in firefox and these are the changes I've done.

<script language="JavaScript" type="text/javascript">
<!--
function changeColor() {
document.bgColor = document.getElementById("color").value;
}
//-->
</script>



Notice the bgColor with a Capital C and document.getElementById.


<input name="color" id="color" type="text" size="15" />


Notice the id added.

For more information on javascript standards, please refer to
http://www.w3.org/DOM/

DOM is the standard for JavaScript set by w3c. If you combine with XHTML, you pages will be in standard with the w3c.

Hope this helps...
Nov 15 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Billy | last post by:
Hello, I'm having a problem dynamically changing the color of a table background. I'm not sure exactly how to word this, but I'll give an example. I have a function called greentored(propname)...
1
by: P.Singh | last post by:
hi all i am designing a website for a charity origanisation. they cater towards the senior crowd. i would like to have choice by which the user can change the background as required (like...
31
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a...
1
by: Omar Llanos | last post by:
How can I change the background color of an MDI form? I read in msdn that it takes the background of windows (and not the BackColor) but I wanted to really make sure. I know that in VC it can be...
4
by: Chris Mahoney | last post by:
Hi Currently I am setting the background image of my page by using the following code: <style type="text/css"> BODY { BACKGROUND-IMAGE: url(myimage.jpg) } </style> What I would like to do...
12
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in...
8
by: Bosconian | last post by:
I have two multiple select inputs. Initially the first contains a bunch of items and the second is empty. Using a common method, I move items back and forth by double clicking on them. This...
4
by: gescom | last post by:
I'm sort of locked into a template from this software my company bought, and it's very restrictive. All color schemes and layouts are site wide only, which creates a bit of a hassle for some pages....
1
by: printline | last post by:
Hi' I have a problem with changing the background color in a table cell when i click on the content in the cell. Here is my code: <script type="text/javascript"> var ie = document.all...
5
by: jeddiki | last post by:
I want to change the default background color of my select box. Here is the problem: Link to form with color select Notice in the color selector, the background color that I have given it it...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.