views:

352

answers:

1

I have created a new YAHOO.util.KeyListener to attach to a specific element and have also created another new YAHOO.util.KeyListener to attach to the entire document. They are both associated with the "enter" key (keys:13).

In the handler function for the listener attached to the specific element, I have the following code:

            getDetailsLocalnameInput = function(e) {
                    getDetails(localnameInput.value);
                    YAHOO.util.Event.preventDefault(e);
                    YAHOO.util.Event.stopPropagation(e);
            };

Yet, the event from the keypress continues to propogate up to the key listener attached to the entire document. I do not want the handler for the key listener attached to the entire document to get kicked off. I am sure that both handlers are being called, but only want the handler attached to the specific element to run.

Is it correct to use YAHOO.util.Event.stopPropagation with YAHOO.util.KeyListener?

Is there a different way I should go about preventing the keypress event from being propogated?

I have also tried using the function YAHOO.util.Event.stopEvent and setting e.cancelBubble with no success.

I have been testing all of this with Firefox 3.5. I cannot get stopPropagation() to work at all.

A: 

Try this:

 getDetailsLocalnameInput = function(e) {
     getDetails(localnameInput.value);

     if(window.event){
         e.cancelBubble=true;//In IE
     }else{
         evt.stopPropagation();//in Others
     }

     //YAHOO.util.Event.preventDefault(e);
     //YAHOO.util.Event.stopPropagation(e);
 };
TheVillageIdiot
`YAHOO.util.Event.stopPropagation` does the same thing. If that doesn’t work, neither will this.
Nate