• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1231
  • Last Modified:

Window.Event.Keycode Returns 'Undefined' in IE6

Can somebody *please* tell me what I'm missing here? I'm trying to call a javascript function in the onKeyPress event of a text box to detect if the ENTER key was pressed. The function successfully executes, however, the window.alert keeps indicating that window.event.keycode is undefined. To narrow down the problem, I created the baby page listed below and it still craps out. What the @*(#$& am I missing here?
function SearchInput_onKeyPress() 
	{
	    window.alert(window.event.keycode);
	    if (window.event.keycode == 13) 
        {
	        searchDirectory();
	    }
	}
 
<html>
<body>
	<input onKeyPress="javascript:window.alert(window.event.keycode);">
</body>
</html>

Open in new window

0
Mick87
Asked:
Mick87
  • 4
  • 2
1 Solution
 
abelCommented:
iirc, this works not well under OnKeyPress, instead, you should use OnKeyDown or OnKeyUp. Reference of how-to is here: http://www.quirksmode.org/js/keys.html
0
 
abelCommented:
oops, sorry, you have a typo. Though my story above holds (but actually is about FF, not IE), you need the following (note the capital C):

function SearchInput_onKeyPress() 
        {
            window.alert(window.event.keyCode);
            if (window.event.keyCode == 13) 
        {
                searchDirectory();
            }
        }

Open in new window

0
 
abelCommented:
and... I see you are testing for code 13, which is Enter. In Internet Explorer, the KeyPress event is not fired for the Enter key.... I know, buggy buggy buggy....

See again that link for details on this for each browser.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
PhatzerCommented:
I've used 'window.event.which' on keypress previously, which has worked well for me, I'm not sure if it makes any difference at all, but it might be worth a shot.
0
 
Mick87Author Commented:
Its an intranet application where IE is the only 'authorized' browser. Although there's nothing stopping someone from downing something else, IT has made it very, very clear that the other browswer's are not and will not be supported.

I ended up changing it to the onKeyUp event.

Is that kosher?
0
 
abelCommented:
> IT has made it very, very clear that the other browswer's are not and will not be supported.
poor you and the other developers... that's gonna cost loads of development time dealing with non-standards behavior. Maybe you can opt to the IT people to say IE8-only? This bug and many other non-conformance bugs have been resolved with IE8.

> Is that kosher?

very kosher ;)
0
 
Mick87Author Commented:
Moving from IE6 to IE8 is not a simple thing given the total IT environment of the organization. What I'm building will be ready before IE8 is even considered. At the point in time were we being the evaluation of IE8, then we'll obviously reevaluate it.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now