473,395 Members | 1,689 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.

Tricky mouseover event for row

Help! I'm a stupid HTML bod and I dont do Javascript!

I have a grey coloured table that displays certain columns in either
red, green or orange to give meaning and emphasis to certain data.

What I want to do now is setup some kind of javascript event so that
when the user mouse's over a row the row changes colour to highlight
it. I've discovered however that I can only change the row into one
specific colour, and then back again into one specific colour using a
mouseover and mouseout event in the row.

I tried moving my event from the row tag into the table cell tags
thinking I was being clever (see below), but had I thought about it
I'd have realised this wasn't going to work either.

Can this actually be done in Javascript as I've exhausted my limited
javascript knowledge and dont know what else to try!

TIA,

Colin

<html>
<head>
<title>MO Test</title>
</head>
<style>

table
{
font-family: Arial;
font-size: 9;
}

td.normal
{
background-color: #C0C0C0;
}

td.normalActive
{
background-color: #B6B6B6;
}
td.high
{
background-color: #F4B6AE;
}

td.highActive
{
background-color: #E8ADA5;
}

td.medium
{
background-color: #EAEE84;
}

td.mediumActive
{
background-color: #DEE27D;
}

td.low
{
background-color: #84EE8E;
}

td.lowActive
{
background-color: #7DE287;
}

</style>

<body>

<table width="500" cellspacing="1">
<tr>
<td onmouseover="this.className='normalActive'"
onmouseout="this.className='normal'"
class="normal">A</td>
<td onmouseover="this.className='highActive'"
onmouseout="this.className='high'"
class="high">90</td>
<td onmouseover="this.className='mediumActive'"
onmouseout="this.className='medium'"
class="medium">50</td>
<td onmouseover="this.className='lowActive'"
onmouseout="this.className='low'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="this.className='normalActive'"
onmouseout="this.className='normal'"
class="normal">A</td>
<td onmouseover="this.className='highActive'"
onmouseout="this.className='high'"
class="high">90</td>
<td onmouseover="this.className='mediumActive'"
onmouseout="this.className='medium'"
class="medium">50</td>
<td onmouseover="this.className='lowActive'"
onmouseout="this.className='low'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="this.className='normalActive'"
onmouseout="this.className='normal'"
class="normal">A</td>
<td onmouseover="this.className='highActive'"
onmouseout="this.className='high'"
class="high">90</td>
<td onmouseover="this.className='mediumActive'"
onmouseout="this.className='medium'"
class="medium">50</td>
<td onmouseover="this.className='lowActive'"
onmouseout="this.className='low'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="this.className='normalActive'"
onmouseout="this.className='normal'"
class="normal">A</td>
<td onmouseover="this.className='highActive'"
onmouseout="this.className='high'"
class="high">90</td>
<td onmouseover="this.className='mediumActive'"
onmouseout="this.className='medium'"
class="medium">50</td>
<td onmouseover="this.className='lowActive'"
onmouseout="this.className='low'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="this.className='normalActive'"
onmouseout="this.className='normal'"
class="normal">A</td>
<td onmouseover="this.className='highActive'"
onmouseout="this.className='high'"
class="high">90</td>
<td onmouseover="this.className='mediumActive'"
onmouseout="this.className='medium'"
class="medium">50</td>
<td onmouseover="this.className='lowActive'"
onmouseout="this.className='low'"
class="low">12</td>
</tr>
</table>

</body>
</html>
Jul 20 '05 #1
3 2274
"Colin Steadman" <go****@colinsteadman.com> wrote:
I have a grey coloured table that displays certain columns in either
red, green or orange to give meaning and emphasis to certain data.

What I want to do now is setup some kind of javascript event so that
when the user mouse's over a row the row changes colour to highlight
it. I've discovered however that I can only change the row into one
specific colour, and then back again into one specific colour using a
mouseover and mouseout event in the row.


I hope this helps:

<html>
<head>
<title>MO Test</title>
</head>
<style>
table
{
font-family: Arial;
font-size: 9;
}
td.normal
{
background-color: #C0C0C0;
}
td.normalActive
{
background-color: #B6B6B6;
}
td.high
{
background-color: #F4B6AE;
}
td.highActive
{
background-color: #E8ADA5;
}
td.medium
{
background-color: #EAEE84;
}
td.mediumActive
{
background-color: #DEE27D;
}
td.low
{
background-color: #84EE8E;
}
td.lowActive
{
background-color: #7DE287;
}
</style>
<script type="text/javascript">
function addEvents(){
var mytable=document.getElementById("mytable");
var rows=mytable.getElementsByTagName("TR");
for (var i=0; i<rows.length;i++){
rows[i].onmouseover=setToActive;
rows[i].onmouseout=setToNormal;
}
}
function setToActive(){
var cells=this.getElementsByTagName("TD");
for (var i=0; i<cells.length; i++){
cells[i].className+="Active";
}
}
function setToNormal(){
var cells=this.getElementsByTagName("TD");
for (var i=0; i<cells.length; i++){

cells[i].className=cells[i].className.substring(0,cells[i].className.length-
6);
}
}
onload=addEvents;
</script>
<body>
<table id="mytable" width="500" cellspacing="1">
<tr>
<td class="normal">A</td>
<td class="high">90</td>
<td class="medium">50</td>
<td class="low">12</td>
</tr>
<tr>
<td class="normal">A</td>
<td class="high">90</td>
<td class="medium">50</td>
<td class="low">12</td>
</tr>
<tr>
<td class="normal">A</td>
<td class="high">90</td>
<td class="medium">50</td>
<td class="low">12</td>
</tr>
<tr>
<td class="normal">A</td>
<td class="high">90</td>
<td class="medium">50</td>
<td class="low">12</td>
</tr>
<tr>
<td class="normal">A</td>
<td class="high">90</td>
<td class="medium">50</td>
<td class="low">12</td>
</tr>
</table>
</body>
</html>
Vjekoslav
Jul 20 '05 #2

"Colin Steadman" <go****@colinsteadman.com> wrote in message
news:40**************************@posting.google.c om...
Help! I'm a stupid HTML bod and I dont do Javascript!

I have a grey coloured table that displays certain columns in either
red, green or orange to give meaning and emphasis to certain data.

What I want to do now is setup some kind of javascript event so that
when the user mouse's over a row the row changes colour to highlight
it. I've discovered however that I can only change the row into one
specific colour, and then back again into one specific colour using a
mouseover and mouseout event in the row.

I tried moving my event from the row tag into the table cell tags
thinking I was being clever (see below), but had I thought about it
I'd have realised this wasn't going to work either.

Can this actually be done in Javascript as I've exhausted my limited
javascript knowledge and dont know what else to try!


Yes. I've adjusted your code below with two short Javascript functions
called on the mouseover and mouseout events:
One to activate each cell in the row and one to disactivate them.

Regards,
Chris.

<html>
<head>
<title>MO Test</title>
</head>
<style>

table
{
font-family: Arial;
font-size: 9;
}

td.normal
{
background-color: #C0C0C0;
}

td.normalActive
{
background-color: #B6B6B6;
}
td.high
{
background-color: #F4B6AE;
}

td.highActive
{
background-color: #E8ADA5;
}

td.medium
{
background-color: #EAEE84;
}

td.mediumActive
{
background-color: #DEE27D;
}

td.low
{
background-color: #84EE8E;
}

td.lowActive
{
background-color: #7DE287;
}

</style>

<body>

<table width="500" cellspacing="1">
<tr>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="normal">A</td>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="high">90</td>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="medium">50</td>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="low">12</td>
</tr>
<tr>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="normal">A</td>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="high">90</td>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="medium">50</td>
<td onmouseover="active(parentNode)"
onmouseout="inactive(parentNode)"
class="low">12</td>
</tr>
</table>

<script>
function inactive(rowObject) {
rowObject.childNodes[0].className="normal";
rowObject.childNodes[1].className="high";
rowObject.childNodes[2].className="medium";
rowObject.childNodes[3].className="low";
}
function active(rowObject) {
rowObject.childNodes[0].className="normalActive";
rowObject.childNodes[1].className="highActive";
rowObject.childNodes[2].className="mediumActive";
rowObject.childNodes[3].className="lowActive";
}

</script>
</body>
</html>


Jul 20 '05 #3
>
Yes. I've adjusted your code below with two short Javascript functions
called on the mouseover and mouseout events:
One to activate each cell in the row and one to disactivate them.

Regards,
Chris.

Thanks Chris, that is exactly the effect I was after. I think I can
see how you've done it to.

Parentnode is presumably the row containing the cell which triggered
the event. And the childnode(s) of row are obviously the cells
themselves, and you are changing the style of these individually.
Very elegant I like it!

I'm going to ask t> Yes. I've adjusted your code below with two short Javascript functions
called on the mouseover and mouseout events:
One to activate each cell in the row and one to disactivate them.

Regards,
Chris.

Thanks Chris, that is exactly the effect I was after. I think I can
see how you've done it to.

Parentnode is presumably the row containing the cell which triggered
the event. And the childnode(s) of row are obviously the cells
themselves. Your functions are simply changing the styles of the
cells very precisely using this information. Very elegant I like it!

Thankyou very much.

Regards,

Colin
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex | last post by:
On my page I have a lot string like this: <span onmouseover="callMe(this)" onmouseout="callMe(null)" >abc1</span> <span onmouseover="callMe(this)" onmouseout="callMe(null)" >abc2</span> <span...
2
by: Mitch | last post by:
I am hosting a web browser ctl in a container that implements the IDocHostUIHandler interface. I'm using this to control the context menu.This works fine. Then, I added a mouseover event to the...
2
by: Dariusz Tomon | last post by:
Hi I got task to make my application much more attractive :( First of all I have to add hover (mouseover) effect to several buttons - imagebuttons - I only know manner with Java Script - but it...
1
by: giloosh | last post by:
Hello All, How can you continue the mouseover event while the mouse is still over an object? For example: I put my mouse over a hyperlink and that triggers an object to move 10px to the right....
10
by: jjamjatra | last post by:
I am struggling with a event model handling problem in Javascript that shows up only in Firefox. I have 2 little websites I'd like you to take a look at: ...
1
by: dheepakk | last post by:
Hi All, When a mouseover event takes place over a link the popup window is displayed. I also have a mouseout on the link.So if the popup window comes up,has a dimension such that the...
2
by: markszlazak | last post by:
I'm a relatively slow response of table cells changing their background color with mouseover/our in IE6 (Win 2K) but the response is fine (fast) in Firefox. Why? The code is below. Sorry about the...
2
by: markszlazak | last post by:
Could someone check out the following code and please help me understand the problem and fix it. It seems like some events are not firing when my mouse moves over the table cells to quickly causing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
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...
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:
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
jinu1996
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...
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...

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.