469,356 Members | 1,958 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Event handler for Enter key

How can I interrupt the enter key so it won't trigger unwanted events on my
web page? I have tried this:

var defaultEventHandler = obj.getEvent("onkeydown");

var myEventHandler = function(event){
if(event.keyCode==13){
alert(obj.getProperty("selection/index"));
}
else{
defaultEventHandler.call(this, event);
}
}
obj.setEvent("onkeydown", myEventHandler);

But it won't even enter the function. Thanks!
Aug 11 '05 #1
3 6787
Simon Wigzell said the following on 8/11/2005 12:19 PM:
How can I interrupt the enter key so it won't trigger unwanted events on my
web page? I have tried this:


Redesign your webpage so that the enter key does not trigger unwanted
events.

What are you really trying to do?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 11 '05 #2
Simon Wigzell wrote:
How can I interrupt the enter key so it won't trigger unwanted events on my
web page?


If I understand correctly you want to set a keypress event handler on
the document and see if the enter key is pressed and in that case
prevent any other events that it may trigger.

This is possible in the DOM2 Event Model, because you can catch events
in the 'capture phase'. However Internet Explorer only supports the
'bubbling phase'.

So to my knowledge what you want is unfortunately not possible.

Robert
Aug 12 '05 #3

"Robert" <ro****@noreply.x> wrote in message
news:42***********************@news.xs4all.nl...
Simon Wigzell wrote:
How can I interrupt the enter key so it won't trigger unwanted events on
my web page?


If I understand correctly you want to set a keypress event handler on the
document and see if the enter key is pressed and in that case prevent any
other events that it may trigger.

This is possible in the DOM2 Event Model, because you can catch events in
the 'capture phase'. However Internet Explorer only supports the 'bubbling
phase'.

So to my knowledge what you want is unfortunately not possible.

Robert


Yes, that is what I wanted, thanks. I'll have to work around it.
Aug 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Alan Zhong | last post: by
3 posts views Thread by R Millman | last post: by
reply views Thread by Francois Malgreve | last post: by
3 posts views Thread by Nikolay Evseev | last post: by
7 posts views Thread by ChrisM | last post: by
4 posts views Thread by federico | last post: by
1 post views Thread by AliR \(VC++ MVP\) | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.