Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a text input field look disabled, but act readonly

Tags:

html

forms

django

I have an HTML input field that I want the user to be able to see, but not edit. If I mark the field as 'disabled', it doesn't get submitted along with the rest of the form. If I mark it as 'readonly', it behaves like what I want, but still looks enabled (at least on Chrome).

Basically, I want the input field to look like a disabled field, but behave as a readonly field. Is this possible?

Thanks.

edit: Also, if I mark it as 'readonly', it's still possible to change its value by double clicking it, and selecting something that was previously there.

like image 745
numegil Avatar asked Oct 12 '11 16:10

numegil


People also ask

How do I make a text field non-editable?

The readonly attribute makes a form control non-editable (or “read only”). A read-only field can't be modified, but, unlike disabled , you can tab into it, highlight it, and copy its contents. Setting the value to null does not remove the effects of the attribute. Instead use removeAttribute('readonly') .

How do I change my input from 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).

How do you make text fields non-editable in CSS?

Solutions with the CSS pointer-events property The second way of making the input text non-editable is using the CSS pointer-events property set to "none", which will stop the pointer-events.


2 Answers

Here is workaround: You have input disabled where you want ( just for displaying value ) and have a hidden input with name and value you need.

like image 187
simoncereska Avatar answered Sep 20 '22 00:09

simoncereska


You could use css to make it look however you want, although this may not match other disabled fields cross browser/platform.

<input type="text" value="Sample text" readonly="readonly" style="color: #787878;"/>
like image 33
neurotik Avatar answered Sep 20 '22 00:09

neurotik