client side handlers

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

Hi,

I know this is not an ASP.NET question, but I thought someone might be able
to help.

I need to handle mouseover events etc for table cells. This is fine and I
can do this ok, my question is ifI can do it easier.

I have a table with hundreds of cells and I dont want to have to render the
whole table with as many onmouseover="functionName(this)" as there are
cells.

Does anyone know of a way of arranging things so that any cell mousover for
example will call the same function but send its own element to the
function. ?

Cheers
 
you can by capturing the mouse, but then you need to walk the dom
calculating what element the mouse is over. this would be too slow.

you could attach the handlers with a simple javascript routine:

var tbl = document.getElementById('tableid');
var cells = tbl.getElementsByTagName('td');
for (var i=0; i < cells.length; ++i)
{
cells.onmouseover = function(){ functionName(this); };
}




-- bruce (sqlwork.com)
 
Thanks Bruce.

Actually, I found that I can simply attach the routine to the TR element,
and then interrogate the event object to discover the srcElement.

Cheers


bruce barker said:
you can by capturing the mouse, but then you need to walk the dom
calculating what element the mouse is over. this would be too slow.

you could attach the handlers with a simple javascript routine:

var tbl = document.getElementById('tableid');
var cells = tbl.getElementsByTagName('td');
for (var i=0; i < cells.length; ++i)
{
cells.onmouseover = function(){ functionName(this); };
}




-- bruce (sqlwork.com)



Just said:
Hi,

I know this is not an ASP.NET question, but I thought someone might be
able to help.

I need to handle mouseover events etc for table cells. This is fine and
I can do this ok, my question is ifI can do it easier.

I have a table with hundreds of cells and I dont want to have to render
the whole table with as many onmouseover="functionName(this)" as there
are cells.

Does anyone know of a way of arranging things so that any cell mousover
for example will call the same function but send its own element to the
function. ?

Cheers
 
Back
Top