By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,044 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,044 IT Pros & Developers. It's quick & easy.

Event handler for Enter key

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a

"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.