Hi,
How can I change the bg color of a table td by javascript? The color is a variable.
e.g.
<head>
<script>
color1="#FF0000";
</script>
</head>
<body>
<table>
<tr>
<td onMouseOver='this.bgColor=color1'>AAA</td>
<td>BBB</td>
</tr>
</table>
</body>
However, I want the color be set when the page is loaded, but not after the mouse events.
Thank you very much.
Frederick 9 8838
"chlaw" <ch***@cse.cuhk.edu.hk> ???????/???????? ? ???????? ?????????:
news:40***************@cse.cuhk.edu.hk... Hi,
How can I change the bg color of a table td by javascript? The color is a
variable. e.g. <head> <script> color1="#FF0000"; </script> </head>
<body> <table> <tr> <td onMouseOver='this.bgColor=color1'>AAA</td> <td>BBB</td> </tr> </table> </body>
However, I want the color be set when the page is loaded, but not after
the mouse events. Thank you very much.
Frederick
<script>
color1='#FAFAFA';
color2='#EEEEEE';
coloradd="'"+color2+"'";
document.write('<td STYLE="background-color:'+color2+'"
onMouseOut="this.style.backgroundColor='+"'"+color 2+"'"+'"
onMouseOver="this.style.backgroundColor='+"'"+colo r1+"'"+'">some
text</td>');
</script>
"Dennis Biletsky" <uf***@ua.fm> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:c9*********@fortress.intercom.net.ua... "chlaw" <ch***@cse.cuhk.edu.hk> ???????/???????? ? ???????? ?????????: news:40***************@cse.cuhk.edu.hk...
[snip] <script> color1='#FAFAFA'; color2='#EEEEEE'; coloradd="'"+color2+"'"; document.write('<td STYLE="background-color:'+color2+'" onMouseOut="this.style.backgroundColor='+"'"+color 2+"'"+'" onMouseOver="this.style.backgroundColor='+"'"+colo r1+"'"+'">some text</td>'); </script>
Sorry "coloradd row" unnecessary. It's mistake ;)
Dennis Biletsky wrote: "Dennis Biletsky" <uf***@ua.fm> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:c9*********@fortress.intercom.net.ua... "chlaw" <ch***@cse.cuhk.edu.hk> ???????/???????? ? ???????? ?????????: news:40***************@cse.cuhk.edu.hk...
[snip] <script> color1='#FAFAFA'; color2='#EEEEEE'; coloradd="'"+color2+"'"; document.write('<td STYLE="background-color:'+color2+'" onMouseOut="this.style.backgroundColor='+"'"+color 2+"'"+'" onMouseOver="this.style.backgroundColor='+"'"+colo r1+"'"+'">some text</td>'); </script> Sorry "coloradd row" unnecessary. It's mistake ;)
Thanks, Dennis.
However, in this way, do I need to move all my html tags into "document.write();" statements ?
I want to minimize the modification on my html file...
Frederick
chlaw wrote: Dennis Biletsky wrote:
"Dennis Biletsky" <uf***@ua.fm> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:c9*********@fortress.intercom.net.ua... "chlaw" <ch***@cse.cuhk.edu.hk> ???????/???????? ? ???????? ?????????: news:40***************@cse.cuhk.edu.hk...
[snip] <script> color1='#FAFAFA'; color2='#EEEEEE'; coloradd="'"+color2+"'"; document.write('<td STYLE="background-color:'+color2+'" onMouseOut="this.style.backgroundColor='+"'"+color 2+"'"+'" onMouseOver="this.style.backgroundColor='+"'"+colo r1+"'"+'">some text</td>'); </script> Sorry "coloradd row" unnecessary. It's mistake ;)
Thanks, Dennis.
However, in this way, do I need to move all my html tags into "document.write();" statements ? I want to minimize the modification on my html file...
Frederick
O, I got it now. Just move the line of document.wirte() inside the <tr></tr>... Thanks.
chlaw <ch***@cse.cuhk.edu.hk> wrote in message news:<40***************@cse.cuhk.edu.hk>... Hi,
How can I change the bg color of a table td by javascript? The color is a variable.
e.g. <head> <script> color1="#FF0000"; </script> </head>
<body> <table> <tr> <td onMouseOver='this.bgColor=color1'>AAA</td> <td>BBB</td> </tr> </table> </body>
However, I want the color be set when the page is loaded, but not after the mouse events. Thank you very much.
Frederick
----------------------------------------------------------------------
Give the desired cell an id name (<TD id="ACELL">xxx</td>
Then, in the javascript, in whatever event you desire (I think you
want it in the onload event in the <BODY> tag) have a line
document.all.ACELL.style.backgroundColor = varColor, where varColor
is your variable color
bruce wrote: chlaw <ch***@cse.cuhk.edu.hk> wrote in message news:<40***************@cse.cuhk.edu.hk>... Hi,
How can I change the bg color of a table td by javascript? The color is a variable.
e.g. <head> <script> color1="#FF0000"; </script> </head>
<body> <table> <tr> <td onMouseOver='this.bgColor=color1'>AAA</td> <td>BBB</td> </tr> </table> </body>
However, I want the color be set when the page is loaded, but not after the mouse events. Thank you very much.
Frederick
---------------------------------------------------------------------- Give the desired cell an id name (<TD id="ACELL">xxx</td>
Then, in the javascript, in whatever event you desire (I think you want it in the onload event in the <BODY> tag) have a line
document.all.ACELL.style.backgroundColor = varColor, where varColor is your variable color
Thanks! It's actually what I want.
bruce wrote: chlaw <ch***@cse.cuhk.edu.hk> wrote in message news:<40***************@cse.cuhk.edu.hk>...
<--snip--> However, I want the color be set when the page is loaded, but not after the mouse events. Thank you very much.
Frederick
---------------------------------------------------------------------- Give the desired cell an id name (<TD id="ACELL">xxx</td>
Then, in the javascript, in whatever event you desire (I think you want it in the onload event in the <BODY> tag) have a line
document.all.ACELL.style.backgroundColor = varColor, where varColor is your variable color
Why not document.getElementById('ACELL').style.backgroundC olor =
so that it works in other browsers as well?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Randy Webb <hi************@aol.com> wrote in message news:<Lt********************@comcast.com>... bruce wrote: chlaw <ch***@cse.cuhk.edu.hk> wrote in message news:<40***************@cse.cuhk.edu.hk>...
<--snip-->
However, I want the color be set when the page is loaded, but not after the mouse events. Thank you very much.
Frederick
---------------------------------------------------------------------- Give the desired cell an id name (<TD id="ACELL">xxx</td>
Then, in the javascript, in whatever event you desire (I think you want it in the onload event in the <BODY> tag) have a line
document.all.ACELL.style.backgroundColor = varColor, where varColor is your variable color
Why not document.getElementById('ACELL').style.backgroundC olor = so that it works in other browsers as well?
My code doesn't recognize any other browsers :) Our systems
assume IE only, so all my answers will too. I should specify that.
Thanks for the additional accuracy.
Dennis Biletsky wrote: <script> color1='#FAFAFA'; color2='#EEEEEE'; coloradd="'"+color2+"'"; document.write('<td STYLE="background-color:'+color2+'" onMouseOut="this.style.backgroundColor='+"'"+color 2+"'"+'" onMouseOver="this.style.backgroundColor='+"'"+colo r1+"'"+'">some text</td>'); </script>
This is invalid HTML. The "script" element misses a "type" attribute
(with the value "text/javascript") and the element it must not occur
as child of "table" or "thead", "tbody", "tfoot" or "tr". Do that
server-side. Anything else is considered harmful.
As for the onmouse* event handlers, this is inefficient, unless only
one table cell is going to be highlighted. I think I have posted a
combination of CSS td:hover and an event listener for the parent "table"
element here previously.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Boris |
last post by:
It is pretty easy to change background color for a text segment of
gtk.TextView, or for entire widget. What I cannot find out - how to change
bgcolor for entire line, from left to right widget...
|
by: kj |
last post by:
Is there a way to dynamically (e.g. upon onClick) change the bgColor
attribute of a table cell? I tried cell.setAttribute("bgColor",
someColor), where someColor was a string of the form "#RRGGBB",...
|
by: @sh |
last post by:
Trying to do this, but its not working...?! My aim being to change the
bgcolor of the cell upon which the user has rolled over, I'll then replicate
this as an OnMouseOut to change it back.
...
|
by: Cliff Cavin |
last post by:
How do I programatically change the background color of an aspx page in
code?
Is there something like Page.BgColor = "#FFFFFF" ?
For that matter, how do I access any of the DOCUMENT...
|
by: Charles Shao |
last post by:
How to chang bgcolor of row when mouse selected a row?
I have a HTML table in the page. I hope to change <tr.bgcolor> when user
clicks on a column, just like user has selected this row.
How...
|
by: acord |
last post by:
Hi,
I want to change the background color of a ul/li row, but the following
code is not working as I expected. It works in <table><tr>...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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,...
| |