View Full Version : Enter key causes form Post
blindbull
09-30-2002, 02:39 PM
Is there a way of stopping the enter key from causing a form post in IE?
I know a possible way is to detect each keydown so perhaps I could check for the chr(32) character but this would be inefficient so is there a better way?
requestcode
09-30-2002, 04:37 PM
Try this script in the head section of your document:
<SCRIPT LANGUAGE="JavaScript">
function KeyDownc(e)
{
var keycodec = event.keyCode
if(keycodec=='13')
{
return false;
}
}
document.onkeypress=KeyDownc;
</SCRIPT>
I believe that should work.
whackaxe
09-30-2002, 04:52 PM
i never managed to get anything with the keydown function using keycode 13. it always just submitted or did nothing
whammy
09-30-2002, 04:55 PM
Instead of disabling the enter key, you should really validate the form using
onsubmit="return validatefunctionname()"
in your form tag.
adios
09-30-2002, 05:06 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function killEnter(e) {
var kC = window.event ? event.keyCode :
e && e.keyCode? e.keyCode:
e && e.which ? e.which : null;
if (kC) return kC != 13;
}
</script>
</head>
<body>
<form>
<input type="text" onkeypress="return killEnter(event)">
<input type="submit">
</form>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.