Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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?

You are here: irt.org | FAQ | JavaScript | Event | Q1425 [ previous next ]

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?'

©2018 Martin Webb