Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: cursor showing in readonly input text?

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?

like image 635
user979672 Avatar asked Oct 27 '11 14:10

user979672


People also ask

How do I make inputs readonly in HTML?

The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).

How do I change a readonly in HTML?

A read-only field cannot be modified. However, a user can tab to it, highlight it, and copy the text from it. Tip: To prevent the user from interacting with the field, use the disabled property instead.


1 Answers

My solution, from nikmd23's jQuery snippet but with the blur() function that seems to work better

$('input[readonly]').focus(function(){     this.blur(); }); 

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

like image 122
Frank Avatar answered Sep 21 '22 22:09

Frank