Reading a Button's Value on Submit

Complex HTML forms often end up with multiple submit buttons. Consider a form for taxes: there’s a button to save a draft and another button to submit for processing. They both trigger the submit action on the same form. How could we accomplish this while keeping the buttons fairly simple? One solution is to set the buttons’ value: <form onsubmit={onSubmit}> <!-- Form fields here --> <input type="submit" value="save" /> <input type="submit" value="submit" /> </form> Then in the submit handler, we read the value. ...

May 24, 2024

Autofocus a Form Field

autofocus is a global attribute that sets a field as focused on page load. <input name="first_name" autofocus /> No JavaScript required! A use case could be a new customer form that an employee fills out multiple times a day. By autofocusing the first name field, you could save that employee thousands of clicks. Carefully consider user experience and accessibility before using this attribute. Docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus

May 21, 2024

Button, Link, or Neither? Three Principles for Clarity and Accessibility

Which HTML elements should we be giving a user to click? In this post, I’ll share some best practices for clickable elements. ...

December 3, 2022

Don’t miss my next essay

Hear from me immediately when I post: no ads, unsubscribe anytime.