473,545 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="th is.className='n ormalActive'"
onmouseout="thi s.className='no rmal'"
class="normal"> A</td>
<td onmouseover="th is.className='h ighActive'"
onmouseout="thi s.className='hi gh'"
class="high">90 </td>
<td onmouseover="th is.className='m ediumActive'"
onmouseout="thi s.className='me dium'"
class="medium"> 50</td>
<td onmouseover="th is.className='l owActive'"
onmouseout="thi s.className='lo w'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="th is.className='n ormalActive'"
onmouseout="thi s.className='no rmal'"
class="normal"> A</td>
<td onmouseover="th is.className='h ighActive'"
onmouseout="thi s.className='hi gh'"
class="high">90 </td>
<td onmouseover="th is.className='m ediumActive'"
onmouseout="thi s.className='me dium'"
class="medium"> 50</td>
<td onmouseover="th is.className='l owActive'"
onmouseout="thi s.className='lo w'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="th is.className='n ormalActive'"
onmouseout="thi s.className='no rmal'"
class="normal"> A</td>
<td onmouseover="th is.className='h ighActive'"
onmouseout="thi s.className='hi gh'"
class="high">90 </td>
<td onmouseover="th is.className='m ediumActive'"
onmouseout="thi s.className='me dium'"
class="medium"> 50</td>
<td onmouseover="th is.className='l owActive'"
onmouseout="thi s.className='lo w'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="th is.className='n ormalActive'"
onmouseout="thi s.className='no rmal'"
class="normal"> A</td>
<td onmouseover="th is.className='h ighActive'"
onmouseout="thi s.className='hi gh'"
class="high">90 </td>
<td onmouseover="th is.className='m ediumActive'"
onmouseout="thi s.className='me dium'"
class="medium"> 50</td>
<td onmouseover="th is.className='l owActive'"
onmouseout="thi s.className='lo w'"
class="low">12</td>
</tr>
<tr>
<td onmouseover="th is.className='n ormalActive'"
onmouseout="thi s.className='no rmal'"
class="normal"> A</td>
<td onmouseover="th is.className='h ighActive'"
onmouseout="thi s.className='hi gh'"
class="high">90 </td>
<td onmouseover="th is.className='m ediumActive'"
onmouseout="thi s.className='me dium'"
class="medium"> 50</td>
<td onmouseover="th is.className='l owActive'"
onmouseout="thi s.className='lo w'"
class="low">12</td>
</tr>
</table>

</body>
</html>
Jul 20 '05 #1
3 2285
"Colin Steadman" <go****@colinst eadman.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=documen t.getElementByI d("mytable");
var rows=mytable.ge tElementsByTagN ame("TR");
for (var i=0; i<rows.length;i ++){
rows[i].onmouseover=se tToActive;
rows[i].onmouseout=set ToNormal;
}
}
function setToActive(){
var cells=this.getE lementsByTagNam e("TD");
for (var i=0; i<cells.length ; i++){
cells[i].className+="Ac tive";
}
}
function setToNormal(){
var cells=this.getE lementsByTagNam e("TD");
for (var i=0; i<cells.length ; i++){

cells[i].className=cell s[i].className.subs tring(0,cells[i].className.leng th-
6);
}
}
onload=addEvent s;
</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****@colinst eadman.com> wrote in message
news:40******** *************** ***@posting.goo gle.com...
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="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="normal"> A</td>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="high">90 </td>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="medium"> 50</td>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="low">12</td>
</tr>
<tr>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="normal"> A</td>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="high">90 </td>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="medium"> 50</td>
<td onmouseover="ac tive(parentNode )"
onmouseout="ina ctive(parentNod e)"
class="low">12</td>
</tr>
</table>

<script>
function inactive(rowObj ect) {
rowObject.child Nodes[0].className="nor mal";
rowObject.child Nodes[1].className="hig h";
rowObject.child Nodes[2].className="med ium";
rowObject.child Nodes[3].className="low ";
}
function active(rowObjec t) {
rowObject.child Nodes[0].className="nor malActive";
rowObject.child Nodes[1].className="hig hActive";
rowObject.child Nodes[2].className="med iumActive";
rowObject.child Nodes[3].className="low Active";
}

</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
3334
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 onmouseover="callMe(this)" onmouseout="callMe(null)" >abc3</span> <span onmouseover="callMe(this)" onmouseout="callMe(null)" >abc4</span> How can I...
2
5162
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 document in the documentComplete event handler. When I add this event handler, I loose all other navigation functions in the browser! right...
2
4474
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 does not work with ASPNET objects. Any ideas? Darek
1
2654
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. I want the object to continue moving 10px to the right every 1 second untill i take my mouse off of the hyperlink.
10
2669
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: http://gis.cbmiweb.com/MexicoExported/default.asp http://gis.cbmiweb.com/MDWmaps/default.asp The issue involves the code behind the "Zoom Box"...
1
4345
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 mouse(currently on the link) falls within the popup edges, the popup starts flickering without totally coming up.This is due to the fact the mouseout and mouseover...
2
3004
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 length. <html> <head> <title>Rapid Blocking Interface</title> <style> .calendar {
2
2276
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 some table cells to stay yellow when you move out of them instead of going back to blue. (Note that I'm using DIV's inside this table because...
0
7475
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7436
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5981
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5341
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
715
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.