Mark,
Thank you.  That was a great help.

For those playing at home, here's what I ended up with that works in
both IE and FireFox...

function TrapKey(evt){
                
        evt = (evt) ? evt : (window.event) ? event : null;
        if (evt)
        {
                                
                var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ?
evt.keyCode :((evt.which) ? evt.which : 0));
                                        
                if(charCode == 13)
                {
                        //do stuff
                        return false;
                }
        }
}

Also, found it helpful to call the function properly - doh!

onKeyPress="javascript:TrapKey(event);" 

Gotta love all those divergent DOMs!

Thanks again.

On 4/15/05, Mark L Keller <[EMAIL PROTECTED]> wrote:
> 
> Hey Dean,
> 
> Try this:
> 
> http://www.severnsolutions.co.uk/twblog/archive/2003/09/14/keypressevents
> 
> Mark
> 
> >From: Dean Fiala <[EMAIL PROTECTED]>
> >Reply-To: [email protected]
> >To: [email protected]
> >Subject: [AspNetAnyQuestionIsOk] Key Capture in Mozilla
> >Date: Fri, 15 Apr 2005 10:51:22 -0400
> >
> >
> >OK,
> >I'm trying to capture a return key being pressed in a text box.
> >
> >I capture the event successfully
> >onKeyPress="javascript:TrapKey();
> >
> >and it calls this function...
> >function TrapKey(e)
> >{
> >     alert('Key Trap Entered');
> >     if(e.keyCode == 13)
> >     {
> >     e.keyCode == 0;
> >     //do some stuff...
> >    }
> >}
> >
> >this works perfectly in IE
> >
> >but in Mozilla the function gets called, but e is always undefined
> >and hence I cannot read the key code.
> >
> >I've done some googling and come up with some variations
> >
> >that try and set e, if it is not defined, but none of these work either,
> >such as
> >
> >if (!e) var e = window.event;
> >
> >Any thoughts or hints would be appreciated.
> >
> >Thanks
> >
> >
> >--
> >Dean Fiala
> >Very Practical Software, Inc
> >http://www.vpsw.com
> >
> >
> >
> >Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 


-- 
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to