Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Assigned Event Handler Not Invoked

Status
Not open for further replies.

jjwild

Programmer
Sep 7, 2001
115
US
I am adding rows to an existing table using Javascript.

The rows display properly, but the javascript I have assigned to handle the onmouseover event is not invoked.

The code I use is the following:

rowNewRow.setAttribute('onmouseover',"rowMOver('2')");

rowNewRow being the variable pointing to the row.

I have also tried:

rowNewRow.onMouseOver = "rowMOver('2')";

After I do this, the value of tblTable.innerHTML shows that the event handler is there in the HTML but it does not get invoked. I have put the same code into the HTML at design time and that works.

Any one have any ideas?

Thanks,

John
 
As a general approach, it can be done like this.
[tt]
if(window.attachEvent) {
rowNewRow.attachEvent("onmouseover",function() {rowMOver('2')});
} else if (window.addEventListener) {
rowNewRow.addEventListener("mouseover", function() {rowMOver('2')},true);
}
[/tt]
 
The basic error was solved by tsuji, though I ended up programming it a different way. Thanks for the help.

My base error was assigning a string value to the event. This:

rowNewRow.onMouseOver = "rowMOver('2')";

should have been this:

rowNewRow.onMouseOver = function() {rowMOver('2')};

I actually used:

rowNewRow.onMouseOver = rowMOver;

To do this, I rewrote rowMOver to use window.event.srcElement to look at the element calling it and find out the value it needed instead. This solved some other issues I had.

Thanks,

John

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top