Web forms are complex beasts. There are a lot of field types to remember, each with dozens of attributes. It’s hard to know which is the right way to go, especially when presented with a choice between two seemingly similar options for disallowing a field to be edited:
disabled
andreadonly
.TL;DR: If you really need it, which you probably don’t,
readonly
is what you want.[…]
The Key Difference
So why do we have two attributes that do the same thing? Unfortunately this is where developers often get confused: the user experience is the same, but the mechanics are quite different.
Fields marked as
readonly
are collected along with all of the normal field values in a form submission (“successful controls” in the spec). The only difference between areadonly
field and a regular field is the user experience.Fields marked as
disabled
are ignored when collecting values from the form. In a traditional form submission, the action page would never receive values for adisabled
field, regardless of whether it has aname
attribute.