By design I need an input element typed text but I do not need an input element typed submit. I want to submit what’s written in the input element once the enter key pressed. How would I do that in JavaScript? Do I need tags and other stuff or could I do it without them (just using )?
Share
In Firefox at least, pushing enter in a
input[type=text]element will submit it.Check it out on JSBin.
You do not need to use JavaScript (maybe in IE, can not test that now).
Also, it’s worth mentioning that all forms should have a submit button. You will need to explicitly tell the user to push enter. Also, what about devices with no enter button? I’ve heard the Zune can not submit forms without a button.
Some people say an exception is the search input box, like on Stack Overflow. However, I think it could still benefit from a small search button or similar.