PDA

View Full Version : Disable ENTER key for form...


Kyle
10-06-2002, 06:48 PM
The following works on IE but not Netscape browser, what can be added to accommodate Netscape as well?:

<head>
<script language="JavaScript1.1">
<!--
// This fuction disable the ENTER key on form
function noenter() {
return !(window.event && window.event.keyCode == 13);
}
// end hiding contents -->
</script>
</head>

<body>
.
.
<form name="jumpform"><a href="javascript:jumpslide()">go to</a><input type="text" size="2" name="jumpfield" onkeypress="return noenter()"></form>
.
.
</body>

Eternity Angel
10-06-2002, 06:52 PM
I dunno about NetScape, because I don't use it, but if you are simply just trying to disable hitting enter to SUBMIT a form, just add onSubmit="return false;" to the <form> tag.

If that ISN'T what you are trying to do, then I can't help you :-(

Philip M
10-06-2002, 08:17 PM
<!-- TWO STEPS TO INSTALL CLICK TO SUBMIT:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Shawn Hafen (shafen@mail.com) -->
<!-- Web Site: http://shafen0.tripod.com/index.html -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function onKeyPress () {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
alert("Please Click on the Submit button to send this");
return false
}
return true
}
document.onkeypress = onKeyPress;
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<input type="text">
<input type=submit>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 1.09 KB -->

Kyle
10-07-2002, 09:22 AM
Thanks but...works on ie5 but still not working on my ns4.61.

glenngv
10-07-2002, 10:35 AM
insert this line before document.onkeypress

if (document.layers) document.captureEvents(Event.KEYPRESS)

Kyle
10-07-2002, 12:49 PM
tried but nope.

realisis
10-07-2002, 01:06 PM
it's also because the function references a parameter without receiving one. Change the function name to this:

function onKeyPress (e)

Kyle
10-07-2002, 02:52 PM
Thx folks, I've got it!