I have an HTML element in my web page on iPad and it must be read only to prevent users updating the content,using readOnly='readOnly'
makes the element unselectable and text content of the element can not be copied at all.
is there any way to make the element read only and the user can select/copy the text content????
According to HTML specs, the select tag in HTML doesn't have a readonly attribute, only a disabled attribute. So if you want to keep the user from changing the dropdown, you have to use disabled .
The readonly attribute of <input> element in HTML is used to specify that the input field is read-only. If an input is readonly, then it's content cannot be changed but can be copied and highlighted. It is a boolean attribute. Example: This example uses HTML <input> readonly Attribute.
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. Another difference is that readonly elements can be focused (and getting focused when "tabbing" through a form) while disabled elements can't.
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') .
just i removed the readOnly
attribute and added the following onkeydown
and oncut
events to simulate readOnly
behavior
<input type="textarea"
onkeydown="event.preventDefault();event.stopPropagation();return false;"
oncut="event.preventDefault();event.stopPropagation();return false;">
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