Forum Moderators: open

Message Too Old, No Replies

catching event on table cell

         

mai_solu

6:22 am on Apr 9, 2003 (gmt 0)

10+ Year Member



hi!
i have a table on which i want to catch event like. on mouseover, onmouseclick and onmousedouble click on each cell.

if anyone have any idea to catch the event. do let me know.
with best regards
Ather Idrees

le_gber

6:54 am on Apr 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just put the event andler inside the <TD> tag, like
<td onMouseOver="action/function here" onMouseOut="action/function here">

Won't work with some older browsers though.

Leo

mai_solu

7:12 am on Apr 9, 2003 (gmt 0)

10+ Year Member



i have a dynamic table, and i want to catch all the event by one function. its not possible to write function for each <TD> tag.
. so looking for GENERIC way to handle event on the table.

with best regards
Ather Idrees

le_gber

7:19 am on Apr 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you mean by dynamic table?

Is it databse driven and then the rows are created by a loop as long as there is data the meet the requirments?

If so you could put event handler inside the loop that creates the rows.

Leo

mai_solu

7:46 am on Apr 9, 2003 (gmt 0)

10+ Year Member



nt coming from the database, but u can say close to that. but logic does not support that , each cell event should be handle independent.

With best regards
Ather Idrees

le_gber

9:37 am on Apr 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well if you can't put a event handler for each <td> with the associated funtion and you want to have each cell reacting independently I'm sorry but I reaaly don't see how.

Leo

joshie76

11:57 am on Apr 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could attach events to the cells in script once the table has loaded, something like this:

var table = document.getElementById('myTableId');

for (var r=0; r < table.rows.length; r++)
{
for (var c=0; c <table.rows(r).cells.length; c++)
{
table.rows(r).cells(c).onmouseover = myEventHandler;
}
}

Though this will only work in later browsers with a good DOM (IE5+, NN6+ etc)

mai_solu

2:55 pm on Apr 9, 2003 (gmt 0)

10+ Year Member



thanks joshie76!
well ur solution can solve the problem. but need to attach a handler to each cell.

but another easier solution is provided by MS. they have provided a component which handle event on the table.
but it IE dependent.
check the link:

[msdn.microsoft.com...]

but i prefer to use ur solution instead of MS. bcz i want to be idependent.

thanks all of u.
with Best Regards
Ather Idrees