Javascript Reference - HTML DOM Input Search disabled Property








The disabled property disables or enables a search field.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = searchObject.disabled

Set the disabled property.

searchObject.disabled=true|false

Property Values

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

Return Value

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





Example

The following code shows how to get if a search field is disabled.


<!DOCTYPE html>
<html>
<body>
Search: <input type="search" id="mySearch" disabled>
<button onclick="myFunction()">test</button>
<!-- w  w  w . ja  v a 2s  .  c o  m-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("mySearch").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 search field.


<!DOCTYPE html>
<html>
<body>
<!--   www. j ava 2 s .  c o  m-->
Search: <input type="search" id="mySearch"><br><br>

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

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

</body>
</html>

The code above is rendered as follows: