views:

98

answers:

2

is there some fix for this

<form>
<input type="text" ...

</form>

hitting the enter key inside the textfield when there is no submit button inside doesn't submit the form, is there some fix for this ?

+6  A: 

My suggestion is.. Create a submit button. If you do not want to show the submit button, then hide the button using CSS.

Muneer
Unfortunately, Chrome (v7.0.517.8 dev) seems to be clever enough to know the submit button is hidden and not listen to the enter key press :-(
Tom
+2  A: 

You could use the keyup event of jquery and if the key pressed is 13 (enter key code) then submit the form:

$('#input-id').keyup(function(e) {
    if (e.keyCode == 13) {
        $('#form-id').submit();
    }
});
despart
This is also a good option but need to implement the keyup even for all elements. This will increase the workload to the browser as well as coding.
Muneer
You could also implement this for all the elements using a class selector, but even though I agree your solution is cleaner and better.
despart