Let's say we have a textbox that's readonly, like so:
<input type="text" readonly />
In IE 9 and FF 4, when I click on this field, a (non-blinking) cursor appears in the field. In Chrome, however, the cursor does not show. (See for yourself at http://jsfiddle.net/hqBsW/.)
I suppose I understand why IE/FF opt to show the cursor—so the user knows he or she can still select the value in the field.
Nonetheless, it's evidently confusing our users and we would like to change IE/FF to not show the cursor, as Chrome does for readonly
fields.
Is there a way to do this?
You can set the style attribute of your tag or you can add a css class to your tag by setting the class attribute's value. Your problem can be solved by setting the cursor. You can read more here. Also, if you have some rules which set the cursor of this tag you can add !important to your css rule. You can read more about !important here.
It can be done using html and javascript
or globally using jQuery
the only way i found for this was
You can use
css
:Reference: https://developer.mozilla.org/pt-BR/docs/Web/CSS/pointer-events
My solution, from nikmd23's jQuery snippet but with the blur() function that seems to work better
Example here: http://jsfiddle.net/eAZa2/
Don't use the attribute "disabled" because the input would not be submitted when it is part of a form
If you change the
readonly
attribute todisabled
, you won't be able to click into the input box and thus won't have a cursor.Depending on the browser, you may not be able to select the text either though.
I've provided examples of the various input states here: http://jsfiddle.net/hqBsW/1/
Another alternative is you could force a text selection when the user focuses on a given input element. This change in control behavior would more easily clue the user into the fact that input is restricted, and allows them to copy very easily if that is the end use case.
Using jQuery you would write the selection code like this:
I've updated the example to show this behavior in action: http://jsfiddle.net/hqBsW/2/