Input Text readOnly Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text


The readOnly property sets or gets whether a text field is read-only.

Set the readOnly property with the following Values

Value Description
true|false? Sets whether a text field should be read-only

Return Value

A Boolean, returns true if the text field is read-only, otherwise it returns false

The following code shows how to Set a text field to read-only:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
Name: <input type="text" id="myText">

<button onclick="myFunction()">Test</button>

function myFunction() {//  w w  w  . j a va  2  m
    document.getElementById("myText").readOnly = true;


Related Tutorials