473,433 Members | 1,930 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,433 software developers and data experts.

Dynamically adding onmouseover, onmouseout events not working

Hi,
I was wondering if anyone would be good enough to have a look at the
following code and tell me if there is something im missing!
drug_list is an array of drug details
table is a reference to a correctly structured table.

The problem is that the onmouseover and onmouseout events are only
being added for the last table row:

function drawTableRow(drug_list,table)
{
//id,abreviation,drug_name,instruction,frequency,amo unt,preperation
var tab_id = table.id;
var t_body = table.getElementsByTagName("tbody")[0];
for (var x=0;x<drug_list.length;x++)
{
new_table_row = document.createElement('tr');
for (var y=0;y<=6;y++)
{
if (y==0)//id as table row id
{
new_table_row.id = tab_id + "_rw_" + drug_list[x][y];
//bind mouseover, out, click events
new_table_row.onmouseover = function() { overTr(new_table_row); }
new_table_row.onmouseout = function() { outTr(new_table_row); }
new_table_row.onmousedown = function() { clickTr(new_table_row); }
alert(new_table_row.id);
t_body.appendChild(new_table_row);
}
else
{
new_td = document.createElement('td');
new_td.innerText = drug_list[x][y];
new_table_row.appendChild(new_td);
}
}
}
table.style.display = "inline";
}

May 21 '06 #1
2 2213


Steve Macleod wrote:

new_table_row = document.createElement('tr');
for (var y=0;y<=6;y++)
{
if (y==0)//id as table row id
{
new_table_row.id = tab_id + "_rw_" + drug_list[x][y];
//bind mouseover, out, click events
new_table_row.onmouseover = function() { overTr(new_table_row); }


Use
new_table_row.onmouseover = function() { overTr(this); }
and the same approach for the other handlers.

--

Martin Honnen
http://JavaScript.FAQTs.com/
May 21 '06 #2
cheers!
it worked

May 21 '06 #3

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

Similar topics

3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
12
by: Epetruk | last post by:
Hi all, I want a page where the contents of a table cell are replaced with an image when the mouse moves over the cell, and the text is restored when the mouse moves out. Here's the html for the...
2
by: Kirk Is | last post by:
Hi there. I'm trying to improve a simple javascript based graphics editor for Atari 2600 games (long story) with better use of CSS and Javascript. I'm a little weak on what CSS can and can't...
10
by: xxbmichae1 | last post by:
I'm having a hard time getting this code to work...the onMouseOver and onMouseOut events don't seem to be firing in IE or Mozilla.....thanks in advance for any assistance... var imgf =...
2
by: MrCode2k | last post by:
Hello, Trying to do: I just want a table that I can scroll and that has fixed headers. Problem: I got it to work but when I added the onmouseover event it didn't work anymore....
7
by: MrCode2k | last post by:
Hello, Trying to do: I just want a table that I can scroll and that has fixed headers. Problem: I got it to work but when I added the onmouseover event it didn't work anymore....
2
by: Daz | last post by:
Hi everyone. I think my problem is a simple one, but I am completely baffled as to how to pull it off. I have a piece of code like so... document.write( "<img id=\"slideshow_toggle\"...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
10
by: AC | last post by:
I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseover = swapMenuSales; // etc } window.onload = prepEvents;
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.