Javascript DOM HTML Input Email readOnly Property set

Introduction

Set an email field to read-only:

document.getElementById("myEmail").readOnly = true;

Click the button to set the email field to read-only.

View in separate window

<!DOCTYPE html>
<html>
<body>

E-mail: <input type="email" id="myEmail">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w w  w  .  j a v  a  2 s  .c o m
  document.getElementById("myEmail").readOnly = true;
}
</script>

</body>
</html>

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

This property mirrors the HTML readonly attribute.

The readOnly property accepts and returns a boolean type value.

Property Values

Value Description
true The email field is read-only
false Default. The email field is not read-only

The readOnly property returns true if the email field is read-only, otherwise it returns false.




PreviousNext

Related