I sometimes find the need to dynamically enable or disable form elements especially since I often use ASP.NET webforms. For this purpose I find that the default HTML attributes are not sufficient.
Specifically, the HTML DISABLED and READONLY element attributes do not work as one would want a disabled form field to actually work. In my opinion if a field is disabled it should not be editable, but it should post back when the form is submitted.
So just to sum up the problem: if you write a Web form with code that receives and handles the form data when it is posted, then you are looking for certain form fields to be sent to you.
To disable a field from being edited by the user you can choose one of two methods:
1) You can tag it with the DISABLED attribute. This sounds more promising than it actually is. The side effect of this attribute is that the form field is just never sent with the post, which can cause a lot of headache with code especially if you are dynamically disabling/enabling fields per user input.
2) You can tag it with the READONLY attribute. This attribute is also a big letdown. If you choose to tag a form field with the READONLY attribute then it will be sent with the post (which is good), but the field is fully editable by the user (very not so good)!
In my opinion both the DISABLED and READONLY tags end up being pretty useless so I am happy to report that a third option exists.
I hope this has been helpful information. Often I will find myself under the gun trying to deliver for a tight deadline, and the last thing I want to be worrying about is how to properly disable form elements!