HTML
html/button-type
Every button states its type (button, submit or reset); the default is submit.
minorstaticfe-html
Why
A <button> with no type submits its form. A "Show password" or "Add row" button inside a form then sends the form by accident, and the bug appears only when the markup is moved into a form later.
Fix
Write type="button" on every button that runs script, and type="submit" on the one that submits, so intent is visible in the markup.
Examples
<!-- bad -->
<button onclick="toggle()">Show password</button>
<!-- good -->
<button type="button" onclick="toggle()">Show password</button>Sources
Facts
- Id
html/button-type- Severity
- minor
- Check
- static checked in the source by
audit - Applies to
htmlangularvuesvelteastrojsx- Taught by the skill
fe-htmlHTML documents and semantics- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain html/button-type