PDA

View Full Version : Resolved Form submit with Enter Key



crobinson42
02-29-2012, 03:48 AM
Hello all, I'm curious if anyone has experienced this frustrating problem; When I make forms, some of them the Enter key works to submit the form in IE 8 and on some of the forms it does not. Am I missing something??

keyboard
02-29-2012, 05:33 AM
Found this



<html>
<head>
<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
myfield.submit();
return false;
}
else
return true;
}
//-->
</SCRIPT>
</head>
<body>
<FORM ACTION="processingpage" onKeyPress="return submitenter(this,event)">
<input type="text"></input>
</FORM>
</body>
</html>


All you need to do is add this onKeyPress="return submitenter(this,event)" to your form tag and this



<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
myfield.submit();
return false;
}
else
return true;
}
//-->
</SCRIPT>


to the head of your document. It'll submit the form onkeypress enter(keycode 13).

The srcipt was from here (http://www.htmlcodetutorial.com/forms/index_famsupp_157.html)
Keyboard1333

crobinson42
02-29-2012, 03:29 PM
Thanks, I was hoping to not have to use script! I guess it's just a bug!?

keyboard
02-29-2012, 11:57 PM
Yes I agree, it can be very frustrating...
At least there's a fairly easy way out of it.

If this thread is finished please set it to Resolved. You can do this by clicking edit on your first post, go advanced, prefixes resolved.

Keyboard1333