W3Schools.com

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 type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE