detecting ENTER

M

mk

Hi

I'v got the following javascript (part of it) that works with the event
onmouseup:

// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;}
}

Now I modified it so it works with onkeydown:

// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;
LICollection.item(l).onkeydown=onMouseUpHandler;}
}

This works fine, but actually I want only that it works whit ENTER
pressed. When I try this:

// Attach event handlers to all images within container
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{ for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;
LICollection.item(l).onkeydown(Key.ENTER)=onMouseUpHandler;}
}

nothing happens anymore?

Any clue for me?
Thanks ajavascript newbee.
Markus
 
E

Elegie

mk wrote:

Hi,
This works fine, but actually I want only that it works whit ENTER
pressed. When I try this:
LICollection.item(l).onkeydown(Key.ENTER)=onMouseUpHandler;}

With this syntax, it's like you'd consider the onkeydown property of the
LI element to be a callable object :) It's not, then rather define and
use the following.
 
R

Richard Cornford

Elegie said:
With this syntax, it's like you'd consider the onkeydown property of the
LI element to be a callable object :) It's not,

It might be. Once the element has been assigned an onkeydown handler it
certainly would be callable. That doesn't help at all as - key.Enter -
is a meaningless argument and you cannot assign to the return value
from a function call anyway.
then rather define and
use the following.

As the element has had an onmouseup handler assigned there is no need
to use the - call - method, as calling that handler directly and
passing the - evt - argument in will sufficiently simulate the mouse
event (and get the - this - reference right):-

this.onmouseup(evt);

Richard.
 
E

Elegie

It might be. Once the element has been assigned an onkeydown handler it
certainly would be callable. That doesn't help at all as - key.Enter -
is a meaningless argument and you cannot assign to the return value
from a function call anyway.

Don't hit too hard, I know I've been weak there :) I didn't want to say
anything in the first place about the construct, and still wanted to
provide the OP with a basic explanation - so I ended in writing, out of
laziness, quite an inappropriate comment :$

As the element has had an onmouseup handler assigned there is no need
to use the - call - method, as calling that handler directly and
passing the - evt - argument in will sufficiently simulate the mouse
event (and get the - this - reference right):-

this.onmouseup(evt);

Yes this is definitely possible, and will indeed avoid the use of 'call'
(which wasn't supported in ancient browsers). However, I have a bad
feeling each time I see such statements, because it generally means the
event-management layer is simplistic. My proposal of course does not
make anything better, however it does express, by its form, that it is
merely a patch to a deeper problem :)


Regards,
Elegie.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top