29

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

5 Answers 5

45

You could use the ReadOnly attribute.

Sign up to request clarification or add additional context in comments.

5 Comments

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
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.
It's not working, you can still select text in the input with readonly attribute
@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 Oh sorry - my bad
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.)

Comments

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.

Comments

3

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

Comments

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

1 Comment

This is wrong, readonly sends the field with the form, disabled doesn't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.