If I have an <input>
field with the readonly
attribute, it still appears with the I-beam text cursor. Is there a way to stop that cursor from showing?
I cant use the disabled
attribute because request.getParameter()
does not work on disabled fields.
The readonly attribute of <input> element is used to specify that the input field is read-only.
A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit.
When a textarea is disabled , it will be ignored by a parent form. However, when a textarea is readonly the contents of the textarea will still be submitted with the form even though the user cannot modify the contents.
Use setAttribute() Method to add the readonly attribute to the form input field using JavaScript. setAttribute() Method: This method adds the defined attribute to an element, and gives it the defined value. If the specified attribute already present, then the value is being set or changed.
The idea of readonly
elements is that you can still read and copy the text, just not edit them. That said, you can change the cursor using CSS attribute selectors. This example will match any input
element with a readonly
attribute:
input[readonly] { cursor: pointer; }
I did not want to override bootstrap's default styles so I came along with the following solution:
My LESS File:
input[readonly] {
&.default-cursor {
cursor: default;
}
}
Or in CSS:
input[readonly].default-cursor {
cursor: default;
}
My HTML:
<input type="text" class="form-control text-xl default-cursor" readonly>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With