Read-only Textbox without Cursor

Read Only Text boxes can be used to prevent editing by User.

Making Textbox read-only by HTML readonly attribute

Example:

Source:

No value is needed for ‘readonly’ attribute but readonly=”readonly” will also work where attribute minimization is not allowed.

There is also a disabled attribute which disables a field . The field cannot be changed but you cannot get any data from that field when form is submitted.

Read-only is the best way to make an interactive field uneditable while still being able to get data from the field.

Only problem with above code is that Cursor/Caret/Pointer is still visible on selecting field .

 

Removing Cursor/Blinking Caret from field when Selected

You can easily removeĀ  cursor by using simple Javascript : onfocus=”this.blur()”

This will prevent your field from getting focused and thus remove the Cursor.

Example:

 

Source:

6 thoughts on “Read-only Textbox without Cursor”

  1. The Textbox without Cursor allows selection and copying. It works great here but when I copy the code into my aspx and run it, it doesn’t allow the selection.
    What could be the problem?

Leave a Reply

Your email address will not be published. Required fields are marked *