Javascript Reference - HTML DOM Input URL disabled Property








The disabled property disables or enables a URL field.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = urlObject.disabled 

Set the disabled property.

urlObject.disabled=true|false

Property Values

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




Return Value

A Boolean type value, true if the URL field is disabled, otherwise false.

Example

The following code shows how to check if a URL field is disabled.


<!DOCTYPE html>
<html>
<body>
<!--from w  w w  .  ja v  a  2 s.co m-->
Homepage: <input type="url" id="myURL" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myURL").disabled;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to disable and enable a URL field.


<!DOCTYPE html>
<html>
<body>
<!-- w  w w  . ja  v a 2s  . c  o  m-->
Homepage: <input type="url" id="myURL"><br><br>

<button onclick="disableBtn()">Disable URL Field</button>
<button onclick="enableBtn()">Enable URL Field</button>

<script>
function disableBtn() {
    document.getElementById("myURL").disabled = true;
}
function enableBtn() {
    document.getElementById("myURL").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: