28

Is it possible for a disabled <input> tag to support text selection?

Nick Heiner
  • 119,074
  • 188
  • 476
  • 699

5 Answers5

44

You could use the ReadOnly attribute.

g.d.d.c
  • 46,865
  • 9
  • 101
  • 111
  • 3
    Probably the only fix. Note that this is not identical to the `disabled` attribute - the value in the field will be submitted to the receiving script – Pekka Jan 18 '11 at 16:58
  • Also notice that readonly field can be modified by a script for example. Think about autocomplete scripts for example: as the field gets focus, the script can show other values that can be chosen. So be careful. – alci May 31 '13 at 14:49
  • 1
    It's not working, you can still select text in the input with `readonly` attribute – KimchiMan Dec 03 '17 at 00:53
  • 2
    @KimchiMan - This question was asked and answered more than 6 years ago. Yes, you can still select the text. That's the _point_. That was _what the OP asked for_. – g.d.d.c Dec 03 '17 at 01:55
  • @g.d.d.c Oh sorry - my bad – KimchiMan Dec 17 '17 at 01:42
20

Based on the HTML spec, it looks like no:

  • Disabled controls do not receive focus.
  • Disabled controls are skipped in tabbing navigation.
  • Disabled controls cannot be successful.

Are you able to use the readonly attribute instead?

(Wow, "4 new answers have been posted"... I think the spec link is helpful, at least.)

Pops
  • 30,199
  • 37
  • 136
  • 151
3

This will depend heavily on the browser. It works fine for me in Chrome and IE8: JSFiddle

Firefox (3.6) seems to be the one browser that doesn't support it. I don't think you can do anything about that.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
3

You may want to use a readonly input and style it with CSS.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
2

readonly="readonly" is your answer

you can remove border in CSS or directly in styles, when you "blocked" this field and it will look like regular text, bring back the look when "unblocked"...

bensiu
  • 24,660
  • 56
  • 77
  • 117