473,788 Members | 2,897 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(dr ug_list,table)
{
//id,abreviation, drug_name,instr uction,frequenc y,amount,preper ation
var tab_id = table.id;
var t_body = table.getElemen tsByTagName("tb ody")[0];
for (var x=0;x<drug_list .length;x++)
{
new_table_row = document.create Element('tr');
for (var y=0;y<=6;y++)
{
if (y==0)//id as table row id
{
new_table_row.i d = tab_id + "_rw_" + drug_list[x][y];
//bind mouseover, out, click events
new_table_row.o nmouseover = function() { overTr(new_tabl e_row); }
new_table_row.o nmouseout = function() { outTr(new_table _row); }
new_table_row.o nmousedown = function() { clickTr(new_tab le_row); }
alert(new_table _row.id);
t_body.appendCh ild(new_table_r ow);
}
else
{
new_td = document.create Element('td');
new_td.innerTex t = drug_list[x][y];
new_table_row.a ppendChild(new_ td);
}
}
}
table.style.dis play = "inline";
}

May 21 '06 #1
2 2242


Steve Macleod wrote:

new_table_row = document.create Element('tr');
for (var y=0;y<=6;y++)
{
if (y==0)//id as table row id
{
new_table_row.i d = tab_id + "_rw_" + drug_list[x][y];
//bind mouseover, out, click events
new_table_row.o nmouseover = function() { overTr(new_tabl e_row); }


Use
new_table_row.o nmouseover = 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
5178
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 within the html document. When the Finish button is clicked, I need to check for any empty input boxes before loading the next aspx page...but it could be no boxes or five boxes, etc.? I've included my html output...if you have any ideas,...
12
12290
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 page: <HTML> <HEAD> <style type="text/css">
2
2383
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 readily do (sometimes I'm stuck in a Netscape 3 world, mentally) so I have a few questions: Say I had an editor with some CSS like this: <html><head> <style type="text/css"> td.edt {background-color: yellow; height: 50px; width:50px}
10
1175
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 = document.createElement("img"); imgf.src = "../files/img.gif"; imgf.style.cursor = "pointer"; imgf.style.border = "1px solid blue"; imgf.title = "Date selector";
2
2729
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. Replicate-Problem: Scrolldown the textbox and put the mouse over a row.
7
2801
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. Replicate-Problem: Scrolldown the textbox and put the mouse over a row.
2
2647
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\" src=\"img/stop_slideshow.png\" " + "onMouseOver=\"src='./img/stop_slideshow_hover.png'\" " + "onMouseOut=\"src='./img/stop_slideshow.png'\" "
7
2533
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 several methods that are working fine. The problem is if I want to dynamically assign an event handler to the object, the event handler is not called. What am I doing wrong? Below is a sample HTML doc with everything in place. <!DOCTYPE HTML PUBLIC...
10
3771
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;
0
9656
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
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
5402
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
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.