Implicit form submission doesn’t work always (#tilPost)

My friend Tom and Robin recently had a discussion in our of our Slack channels about implicit form submissions. An implicit form submission is the action of just pressing the ENTER key when focussing an input element. It turns out t…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

My friend Tom and Robin recently had a discussion in our of our Slack channels about implicit form submissions. An implicit form submission is the action of just pressing the ENTER key when focussing an input element. It turns out that this is only possible under two conditions:

  • the form has a submit button
  • the form has only one input element

So let me quickly share Tom's example.

<form onsubmit="alert(1)">
  <!-- this will alert if you press enter while "foo" is focused -->
  <input name="foo" />
</form>

<form onsubmit="alert(2)">
  <!-- this won't -->
  <input name="foo" />
  <input name="bar" />
</form>

You could work around this behavior by adding a hidden submit button. But still... this behavior surprised me.

I didn't know about it and it's defined in the spec. Good to know!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2017-05-09T22:00:00+00:00) Implicit form submission doesn’t work always (#tilPost). Retrieved from https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/

MLA
" » Implicit form submission doesn’t work always (#tilPost)." Stefan Judis | Sciencx - Tuesday May 9, 2017, https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/
HARVARD
Stefan Judis | Sciencx Tuesday May 9, 2017 » Implicit form submission doesn’t work always (#tilPost)., viewed ,<https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » Implicit form submission doesn’t work always (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/
CHICAGO
" » Implicit form submission doesn’t work always (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/
IEEE
" » Implicit form submission doesn’t work always (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/. [Accessed: ]
rf:citation
» Implicit form submission doesn’t work always (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2017/05/09/implicit-form-submission-doesnt-work-always-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.