Javascript Reference - HTML DOM Input URL readOnly Property








The readOnly property sets or gets whether or not a URL field should be read-only.

Browser Support

readOnly Yes 10.0 Yes Yes Yes

Syntax

Return the readOnly property.

var v = urlObject.readOnly

Set the readOnly property.

urlObject.readOnly=true|false

Property Values

Value Description
true|false Set whether or not a URL field should be read-only
  • true - The URL field is read-only
  • false - Default. The URL field is not read-only




Return Value

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

Example

The following code shows how to check if a URL field is read-only or not.


<!DOCTYPE html>
<html>
<body>
<!--from   w  w w.  j av a 2  s.  c om-->
Homepage: <input type="url" id="myURL" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myURL").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 a URL field to read-only.


<!DOCTYPE html>
<html>
<body>
<!--  w w  w  . j a v  a 2  s. c om-->
Homepage: <input type="url" id="myURL">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    document.getElementById("myURL").readOnly = true;
}
</script>
</body>
</html>

The code above is rendered as follows: