HTML form :: difference between disabled and readonly element
October 5, 2008 — Arafat Rahman
I was working with HTML forms. In the forms I used readonly and disabled input elements. What is the deference between these two attributes of input element?
Say for I have an input element in HTML form.
<input type="text" name="full_name" value="My Name Here" readonly="readonly" />
If we set the attribute readonly=”readonly“ then the input element is not editable. This attribute allows the user to highlight and copy the text inside the input field, but not change the value.
This attribute is only used if the type attribute of the input element is set to “text” or “password”.
I have another text field like bellow.
<input type="text" name="email" value="my@email.here" disabled="disabled" />
If we set the attribut disabled="disabled", the input element is disabled, un-editable and un-selectable. This attribute not allow the users to highlight and copy the text inside the input field. Another thing happen here, the data within the input element will not be submitted to the action page.








October 7, 2008 at 12:57 am
Though it is a simple thing, sometimes we the developers forget.
October 8, 2008 at 12:31 am
one things, you can set java script event in readonly elements but can’t disabled elements..
October 8, 2008 at 12:34 am
Thanks ism for your comment.
October 8, 2008 at 10:30 am
I agree with Mehedi. Sometimes we search errors in complex things overlooking this type of mistakes. I remember once I faced an issue with disabled field. The data was not coming to my script. After examining my PHP script I found the issue with my HTML disabled field.
October 8, 2008 at 11:05 am
I also experienced some difficulties regarding `readonly` and `disabled`. I had to spend a long span of time to find out why my disabled field is not submitting value to action page then realized the thing.
November 3, 2008 at 2:56 pm
Hi,
hope this fits this pages intentions.
I have a form that after submitting sets the fiels to readonly. Problem is that the field are selectable on at the time, but not all together. That’s a problem, because users can’t copy/paste values into a spreadsheet program, like Excel.
Any suggestions?
Regards, Martin.
November 3, 2008 at 6:51 pm
Hi,
turns out you can’t copy paste like my clients want. I’ll have to put the values direcly in a table cell.
Work work …