JSP / servlet combination doesn’t submit form on Enter if only form element is a submit button
This is a follow on to my previous question:
JSP / servlet / IE combination doesn’t submit form detail on Enter
Inside the form, we have:
<input ... type="submit" name="confirm" value="Confirm"/>
There are no input fields on this form. This form appears at the end of a workflow and is essentially a verification to proceed.
This form is not submitted to either IE or Firefox when the Enter key is pressed. It works perfectly if the "Confirm" button is pressed.
Following on the answer to my previous question开发者_如何学运维, I have tried adding dummy fields such as:
<input type="hidden" />
or
<input type="text" style="display: none;" />
but they make no difference.
For various reasons, we would prefer not to use Javascript.
Any suggestions to get the Enter key to submit?
Unfortunately, you should have at least one focusable input element in the form to get that to work and then only when the input has focus. If you don't have any input elements, then there's no other way to get around this than by letting Javascript to listen on the enter key in the body.
<body onkeypress="if (event.keyCode == 13) document.formname.confirm.click();">
Where formname
is the value of the name
attribute of the parent <form>
element.
Note that I used document.formname.confirm.click()
instead of document.formname.submit()
, because otherwise IE wouldn't send the name=value pair of the button to the server side.
The only Javascript-free way would be to let the user to tab to the button and then press enter. This all is by the way regardless of the browser used and thus not IE specific.
精彩评论