2

I have a form with a <textarea required>, <input type="checkbox">, <input type="text">, and <button type="submit">.

It's all fancified with jQuery, so that if you're in the text-input, or tab to the checkbox, and hit Enter, I catch that and preventDefault so the form doesn't submit.

But I want the form to be equally sensible for people who aren't running Javascript. Surely there is some markup or CSS to indicate that a given form element shouldn't cause form submission?

idupree
  • 730
  • 5
  • 16
  • What? What's sensible about making Enter not submit a form when it works like that everywhere else in the browser (and wider operating system)? Please leave default form behaviours alone. – bobince Oct 22 '11 at 18:40
  • It's a feedback form. The textarea is required (the feedback!), the name/email/do-you give-permission-for-me-to-share-your-feedback parts are optional and off to the side. "Enter" when in the textarea doesn't do anything but add a linebreak (default behaviour!). I don't personally expect that hitting "enter" -- *only* while in the "name" field -- submits the *feedback*. Do we have evidence about average users? – idupree Oct 22 '11 at 19:46
  • In today's browsers and operating systems, pressing Enter in a single-line text field submits the form, pressing Enter in a textarea puts a newline in and doesn't submit the form. This is completely standard behaviour and, whether you agree with it or not, it's more unexpected when you don't behave like the standard. – bobince Oct 22 '11 at 19:54
  • (Or evidence about googlebot/mouse-only/keyboard-only/visual/aural/etc. users. With all sorts of UAs. I'm hoping to be able to support everyone well, as best I can.) – idupree Oct 22 '11 at 19:55
  • @bobince (You have a lot of people to argue against, even if your choice is best. http://stackoverflow.com/questions/895171/prevent-users-from-submitting-form-by-hitting-enter , and several similar questions.) – idupree Oct 22 '11 at 20:08
  • Later I'll ask on SO about the tradeoffs of the different behaviours (unless there's an equivalent question already). – idupree Oct 22 '11 at 20:52

1 Answers1

0

Only javascript accepts events.

You must validate using server-side when you don't have javascript actived.

Caio Tarifa
  • 5,973
  • 11
  • 46
  • 73
  • This is not about validating (I do that server-side), but about providing a nice user experience (helping the user avoid accidentally sending off a POST request and loading another page when they didn't intend to). – idupree Oct 22 '11 at 19:36