[thelist] Cancelling onKeyDown in Netscape 6

MILLER David R. dmiller at mcc.ca
Mon Nov 19 12:52:01 CST 2001


I have little experience with Netscape 6, but here's what I have done in a
similar situation. Assuming that you can rely on JS being enabled, give your
form tag an onSubmit="return false". That will prevent the enter key from
submitting the form. Then in your JS validation routine, presumably
triggered from the submit button's or another button's onClick event, set
form.onsubmit="return true" before returning true from the validation
function or submitting the form explicitly. HTH

---------------FROM-------------------
David R. Miller
Manager, Computer-Based Testing
Medical Council of Canada
dmiller at mcc.ca
-----------------------------------------

Original message
Message: 4
Date: Sun, 18 Nov 2001 18:09:22 -0800
From: "Matt Feldman" <mfeldman at wwwood.net>
Subject: [thelist] Cancelling onKeyDown in Netscape 6

I'm trying to stop a form from submitting when the user presses enter on
a text field.  In IE 5 and Netscape 4, I have a working solution: in the
onKeyDown attribute I call this function:

	function cancelEnter(evt) {
		if (evt.keyCode == 13) {
			return false;
		}
	}

I have to replace the evt.keyCode with evt.which in Netscape 4, but
that's not a problem.  In Netscape 6, however, it catches the event
fine, but returning false does not cancel the form submit.  I know this
has something to do with event bubbling, but I don't know enough about
it to solve the problem.

Any suggestions?

-Matt




More information about the thelist mailing list