Javascript Reference - HTML DOM Input Email readOnly Property








The readOnly property sets or gets whether an email field should be read-only.

Browser Support

readOnly Yes 10.0 Yes Yes Yes

Syntax

Return the readOnly property.

var v = emailObject.readOnly

Set the readOnly property.

emailObject.readOnly=true|false

Property Values

Value Description
true|false Set whether an email field should be read-only
  • true - The email field is read-only
  • false - Default. The email field is not read-only




Return Value

A Boolean type value, true if the email field is read-only, otherwise false.

Example

The following code shows how to get if an email field is read-only.


<!DOCTYPE html>
<html>
<body>
<!--   w  w  w.  jav  a 2  s.  co m-->
E-mail: <input type="email" id="myEmail" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myEmail").readOnly;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to set an email field to be read-only.


<!DOCTYPE html>
<html>
<body>
<!--  ww  w . j  a va  2s  .  c  o m-->
E-mail: <input type="email" id="myEmail">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    document.getElementById("myEmail").readOnly = true;
}
</script>

</body>
</html>

The code above is rendered as follows: