Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1425 Does the window.event.keyCode and the e.which not give 13 in both browsers when the enter key is pressed in a form field?

irt.org | Knowledge Base | JavaScript | Event | Q1425 [ previous next ]

Q1425 Does the window.event.keyCode and the e.which not give 13 in both browsers when the enter key is pressed in a form field?

For some reason I thought this didn't work in Netscape - and it doesn't on Linux with text form fields, but it does on Linux with a textarea:

<head>
<script language="JavaScript1.2"><!--
function netscapeKeyPress(e) {
     if (e.which == 13)
         document.testForm.submit();
}

function microsoftKeyPress() {
    if (window.event.keyCode == 13)
         document.testForm.submit();
}

if (navigator.appName == 'Netscape') {
    window.captureEvents(Event.KEYPRESS);
    window.onKeyPress = netscapeKeyPress;
}
//--></script>

</head>

<body onKeyPress="microsoftKeyPress()">

<form name="testForm">
Lots of text form fields:
<br><input type="text">
<br><input type="text">
<br><input type="text">
<br><input type="text">
<br><input type="text">
<br><input type="text">
<br><input type="text">
<br>And a textarea:
<br><textarea></textarea>
</form>

Ed Eddington writes:

My problem was a related issue:

How to overcome key event unreliability for form fields inside tables with Netscape Navigator 4?

http://www.faqts.com/knowledge-base/view.phtml/aid/5491/fid/145/lang/en

Feedback on 'Q1425 Does the window.event.keyCode and the e.which not give 13 in both browsers when the enter key is pressed in a form field?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.