Search w3schools.com:

SHARE THIS PAGE

Text readOnly Property

Text Object Reference Text Object

The readOnly property sets or returns whether a text field is read-only, or not.

A read-only field cannot be modified. However, a user can tab to it, highlight it, and copy the text from it.

Tip: To prevent the user from interacting with the field, use the disabled property instead.

Syntax

Set the readOnly property:

textObject.readOnly=true|false

Return the readOnly property:

textObject.readOnly


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The readOnly property is supported in all major browsers.


Example

Example

Set a text field to be read-only:

<html>
<head>
<script>
function setResult()
{
document.getElementById("email").readOnly=true;
}
</script>
</head>
<body>

<form>
Email: <input type="text" id="email">
</form>

<button type="button" onclick="setResult()">Set read-only</button>

</body>
</html>

Try it yourself »


Text Object Reference Text Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]