2007-09-20
Submit Form on Enter Key
uh... did you know that you can't submit a form by pressing Enter when having more then 1 input field?
So let's say you have a simple form like this:
-
<form action="" method="post">
-
<input type="text" />
-
</form>
Now when the input text has the focus and you press Enter this form will submit. But once you have more than just one input field, it will not.
-
<form action="" method="post">
-
<input type="text" name="a" />
-
<input type="text" name="b" />
-
</form>
I solved this by adding an invisible submit item.
-
<input type="submit" style="width:0px;height:0px;border:none">
Crazy, but I did not know that.
10 Comments
-
This worked best in Safari, Opera, Firefox and IE:
style=”width: 0px; height: 0px; position: absolute; left: -50px; top: -50px;”
Absolute positioning became necessary because the button was still visible in Firefox and Safari and in particular Safari completely crashed when clicking the button having an empty value attribute.
