473,700 Members | 2,664 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 2296
"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
3351
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 optimize it? Is it possible to move this definition what to do to style/css or some other common...
2
5173
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 click, left click, it's all dead. (The mouseover works though)
2
4484
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
2660
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
2687
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" icon on the "toolbar" near the top of each page. On both pages above, the ZoomBox
1
4351
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 events are triggered again due to interference of the generated popup with the mouse pointer. ...
2
3023
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
2285
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 the lightyellow one will contain an image that will be mousedowned on to start a cell selection mode...
0
8648
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9217
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7815
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5903
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4407
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2393
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2031
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.