Read more

Be careful when using buttons without a "type" attribute

Tobias Kraze
March 10, 2015Software engineer at makandra GmbH

Be careful when using buttons without a type attribute, since browsers will consider them the default submit button of a form.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Suppose you have this form:

<form action="/save">
  <input type="text" />
  <button onclick="alert('Alert!')">Alert</button>
  <button type="submit">Save</button>
</form>

If you press the enter key inside in the text input, browsers will trigger the first button and show the alert.

To fix this, add a type="button" attribute to the first button.

Posted by Tobias Kraze to makandra dev (2015-03-10 10:34)