Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove text caret/pointer from focused readonly input

I am using an <input readonly="readonly">, styled as normal text to remove the appearance of an interactive field, but still display the value.

This is very useful to prevent a user from editing a field, while still being able to post the value. I realize this is a convenience method and that there are several workarounds, but I want to use this method.

Problem: The blinking caret still appears when the field is clicked/focused. (At least in FF and IE8 on Win7)

Ideally, I would like it to behave as it normally does, focusable, but without the blinking caret.

Javascript solutions welcome.

like image 473
Wesley Murch Avatar asked Mar 26 '11 17:03

Wesley Murch


People also ask

How do you remove input field focus?

The blur() method removes focus from an element.

How do I change the input field to read only?

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


2 Answers

On mine there is no caret or so:

<input type="text" value="test" readonly="readonly" > 

Take a look at this: http://www.cs.tut.fi/~jkorpela/forms/readonly.html

Sorry, now I understand your problem.

Try this:

<input type="text" value="test" onfocus="this.blur()" readonly="readonly" > 
like image 101
n3on Avatar answered Oct 05 '22 09:10

n3on


You can use this in your css, but it will not focus:

[readonly='readonly'] {    pointer-events: none; } 
like image 32
Headache Avatar answered Oct 05 '22 08:10

Headache