HTML form :: difference between disabled and readonly element

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 attribute 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.

Share and Enjoy:
  • Facebook
  • Twitter
  • Google Bookmarks
  • Digg
  • del.icio.us
  • MySpace
  • LinkedIn
  • Live
  • Ping.fm
  • YahooMyWeb
  • Posterous
  • Sphinn
  • Mixx
  • DZone
  • email
  • Furl
  • StumbleUpon
  • Technorati
  • TwitThis
  • Webnews.de
  • Yahoo! Buzz
  • blogmarks
  • Yahoo! Bookmarks

7 Responses to “HTML form :: difference between disabled and readonly element”

  1. Mehedi Says:

    Though it is a simple thing, sometimes we the developers forget.

  2. ism Says:

    one things, you can set java script event in readonly elements but can’t disabled elements..

  3. Arafat Rahman Says:

    Thanks ism for your comment.

  4. Sajjad Hossain Says:

    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. :D

  5. Rahat Bashir Says:

    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.

  6. Martin Says:

    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.

  7. Martin Says:

    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 …

Leave a Reply