Closed Bug 58444 Opened 24 years ago Closed 24 years ago

onkeypress doesn't returns proper code for ENTER

Categories

(Core :: DOM: UI Events & Focus Handling, defect, P3)

x86
Windows 2000
defect

Tracking

()

VERIFIED DUPLICATE of bug 58709

People

(Reporter: vsalvador, Assigned: joki)

Details

onkeypress event returns 0 for ENTER key code.

I include the test page...

<HTML>
<HEAD>
<SCRIPT language="JavaScript1.2" type="text/javascript">
var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
parseInt(navigator.appVersion) >= 4) ? 1 : 0;

function doKey(e) {
	 var keyCode;
	 if (e)
		keyCode = e.which;
	 else
		keyCode = window.event.keyCode;
	 alert("KEY Code: " + keyCode)
	 return true;
}

function init() {
	if (isMinNS4) {
		document.captureEvents(Event.KEYPRESS)
	}
	document.onkeypress  = doKey;
}
		
</script> </HEAD>
<BODY onload="init()">
<FORM>
<INPUT TYPE="TEXT">
</FORM>
</BODY>
</HTML>

Press ENTER on the Input field and the alert displays Key code = 0. It should
be "13".

Other bug on the same page and the same event. If you think you must split it on
other bug id please do it yourself:

1. Press any key on the input field. The alert window appears. Then press other
key and the alert window doesn't appears. The event has been deactivated. Now
click with the mouse inside the input field and then the event works again. This
seems like the event needs that the field get focus to activate.
I'm not sure if this is a valid bug.  For a keypress event you should *first* be
checking for a *charcode* (not a keycode).  Keycodes are only guaranteed to be
set for keydown and keyup events.
But this is how it works on IE4, IE5 and NS4 browsers
*** Bug 58709 has been marked as a duplicate of this bug. ***
This is a dupe. The dupe points a problem in a high vis page so making this a
dupe of that even though this was first...

*** This bug has been marked as a duplicate of 58709 ***
Status: UNCONFIRMED → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
Verified dupe.
Status: RESOLVED → VERIFIED
Component: Event Handling → User events and focus handling
You need to log in before you can comment on or make changes to this bug.