Event handler for Enter key

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Wigzell

    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 defaultEventHan dler = obj.getEvent("o nkeydown");

    var myEventHandler = function(event) {
    if(event.keyCod e==13){
    alert(obj.getPr operty("selecti on/index"));
    }
    else{
    defaultEventHan dler.call(this, event);
    }
    }
    obj.setEvent("o nkeydown", myEventHandler) ;

    But it won't even enter the function. Thanks!


  • Randy Webb

    #2
    Re: Event handler for Enter key

    Simon Wigzell said the following on 8/11/2005 12:19 PM:[color=blue]
    > How can I interrupt the enter key so it won't trigger unwanted events on my
    > web page? I have tried this:[/color]

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

    What are you really trying to do?

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

    Comment

    • Robert

      #3
      Re: Event handler for Enter key

      Simon Wigzell wrote:[color=blue]
      > How can I interrupt the enter key so it won't trigger unwanted events on my
      > web page?[/color]

      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

      Comment

      • Simon Wigzell

        #4
        Re: Event handler for Enter key


        "Robert" <robert@noreply .x> wrote in message
        news:42fc5e8a$0 $11071$e4fe514c @news.xs4all.nl ...[color=blue]
        > Simon Wigzell wrote:[color=green]
        >> How can I interrupt the enter key so it won't trigger unwanted events on
        >> my web page?[/color]
        >
        > 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[/color]

        Yes, that is what I wanted, thanks. I'll have to work around it.


        Comment

        Working...